Posts by Michel Meeuwissen

Introduction to Spring profiles

Posted on by  
Michel Meeuwissen

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. Annotations @Component or @Configuration annotated beans can contain the annotation @Profile to only load them in a certain environment.

public class LDAPAuthentication {
   public LDAPAuthentication() {
      System.out.println("LDAP Authentication set by annotations");

public class SAMLAuthentication {
   public SAMLAuthentication() {
      System.out.println("SAML Authentication set by annotations");

Continue reading →