To use annotations for configuring your application, one can use:
AnnotationApplicationContext
which accepts a Ant-style pattern of class names which will scanned for annotations:
ApplicationContext oneConfig = new AnnotationApplicationContext(SimpleConfiguration.class.getName()); ApplicationContext aBunchOfConfigs = new AnnotationApplicationContext("**/configuration/*Configuration.class");
This specialized application context will automatically read and add as beans the classpath classes matching the given pattern. The downside of this approach is that no parameterization of the configuration instances can be made.
Configuration post processor
<beans> <!-- Spring configuration --> <bean class="org.springframework.samples.petclinic.JdbcConfiguration"/> <!-- Java Configuration post processor --> <bean class="org.springframework.config.java.process.ConfigurationPostProcessor"/> </beans>
This second approach allows more configuration options ,as it gives control not just over the configuration processing (through ConfigurationPostProcessor) but also over the configuration instance itself.
By defining the configuration as a bean, the Spring container can be used for configuring the configuration (set properties or use a certain constructor):
<beans> <!-- a possible configurable configuration --> <bean class="org.my.company.config.AppConfiguration"> <property name="env" value="TESTING"/> <property name="monitoring" value="true"/> <property name="certificates" value="classpath:/META-INF/config/MyCompany.certs"/> </bean> <!-- Java Configuration post processor --> <bean class="org.springframework.config.java.process.ConfigurationPostProcessor"/> </beans>