About Michel Meeuwissen

Hi, My name is Michel Meeuwissen. I'm a proud member of the JDriven company. JDriven gives me the opportunity to develop efficient software for the most interesting companies in the Netherlands. Based on historical projects I'm focused on the Spring framework and front-end technologies. Besides my coding skills I also like to learn more about full stack development. You are able to contact me by LinkedIn.

Introduction to Spring profiles

So many men, so many minds. When we are implementing software for different customers we sometimes need to handle various requirements for the same project. For example Customer A needs SAML authentication and customer B needs LDAP authentication.

With Spring Profiles (available from Spring 3.1) we are able to provide a way to segregate parts of our implemented application configuration. This blog will help us to make certain code or rather certain Spring beans only available for specific requirements. For example the example used in this blog can be used to activate the required authentication provider for the provider manager when using Spring Security.

Profiles can be configured by annotations and/or by xml.

@Component or @Configuration annotated beans can contain the annotation @Profile to only load them in a certain environment.

Probably not used anymore in freshly started projects, but it is also possible to make certain Spring beans only available within your XML configuration.

Activate correct profile
Of course you are able to combine both configurations, but is should be obvious to choose one configuration to make your code more predictable . Just to show the possibilities we have combined them in one project.In a plain Java application the profiles can be setup by activating the profile in your application context.

See the following github for the full source of this project: