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.

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

XML
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:
https://github.com/michelmeeuwissen/Spring-Profiles-Intro

 

Keynote SpringOne 2GX

Juergen Hoeller
Hoeller begint zijn presentatie met de originele driehoek van spring. Zijn verhaal beschrijft vervolgens de transitie die het framework heeft gemaakt sinds dat model naar een annotation framework. Hij legt de nadruk vooral ook bij de beschrijvende namen van de annotaties, en hoe ze zorgvuldig zijn gekozen om de code leesbaarder te maken.

Hierbij gaat hij dieper in op een aantalannotaties zoals stereotypes, injections en ook parameter annotaties. Hierbij geeft hij aan het gevoel te hebben dat de kracht van deze annotaties nog steeds wel onderschat wordt.

Continue reading