Load Spring Beans Based On Different Profiles Via XML1 min read


While working on a legacy project, sometimes it becomes so hard to find such small pieces of stuff. Recently I faced a similar problem where I had to load spring beans based on the loaded profiles respectively.

With Spring Boot and annotation, it has become really easy. Just put the @Profile("profile1, profile2") and it works. Similarly, it is done in XML as well. All you need is a bit of knowledge to do so.

So, if you have an XML with application-beans and you want to load different beans based on different profiles then simply wrap the beans under <beans profile="profile1">.

Here’s the example of the same:

(line 38 and line 58 is where the wrapping is performed)

I hope I’ve considered a correct example as it displays the beans loaded by default, loaded based on different profiles.

Let me know in the comments below.


  • Article By: Varun Shrivastava

  • Varun Shrivastava is an innovative Full Stack Developer at ThoughtWorks with around 4 years of experience in building enterprise software systems in finance and retail domain. Experienced in design, development, and deployment of scalable software. He is a passionate blogger and loves to write about philosophy, programming, tech and relationships. This is his space, you can get in touch with him here anytime you want.
  • Website Search



  • Grab the Deal Now!

    Hostgator  Starting @$3.95/mo

  • DigitalOcean Free Credits!