Use of Spring annotation @Configuration

From Spring3.0, @Configuration is used to define configuration classes and can replace xml configuration files. The annotated class contains one or more @Bean annotated methods. These methods will be scanned by AnnotationConfigApplicationContext or AnnotationConfigWebApplicationContext classes and used To build the bean definition, initialize the Spring container.

Note: @Configuration annotated configuration class has the following requirements:

  1. @Configuration cannot be a final type;
  2. @Configuration cannot be an anonymous class;
  3. The nested configuration must be a static class.

1. Use @Configuration to load spring
1.1, @Configuration configure spring and start spring container
1.2, @Configuration start container + @Bean register Bean
1.3, @Configuration start container + @Component register Bean
1.4, use AnnotationConfigApplicationContext to register AppContext class two methods
1.5. Configure the web application (AnnotationConfigApplicationContext is configured in web.xml)

2. Combine multiple configuration classes
2.1, introduce spring xml configuration file
in @configuration 2.2, introduce other annotation configuration in @configuration
2.3, @configuration nesting (nested Configuration must be a static class)
3. @EnableXXX annotation
Four, @Profile logical group configuration
5. Use external variables

Guess you like

Origin blog.csdn.net/LOVE_Me__/article/details/108406188