@EnableAutoConfiguration
开启Spring Application Context自动配置,系统会根据你引入的jar包情况,自动配置一些需要的bean。参考spring-boot-autoconfigure.jar 下的 META-INF/spring.factories
@Configuration
注解在类上,让该类功能类似于代替之前的applicationContext.xml成为配置类。在配置类中可以在类方法上加@Bean注解,将方法返回的bean注入ioc容器。
@ConfigurationProperties(prefix = "test")
指定类初始化的前缀,可单独作用在类上,也可作用在上边提到的@Bean方法上。默认会在application.properties中寻找以test.xxx开头的配置项,将其用于bean属性的初始化,bean属性名字要和xxx一致,并提供该属性的getter和setter方法。
@EnableConfigurationProperties(xxx.class)
启用@ConfigurationProperties注解的bean。如果某个类仅仅注解了@ConfigurationProperties,那他还需要用@EnableConfigurationProperties来开启。如果这个类除了注解了@ConfigurationProperties,还注解了@Bean或者@Component、@Service之类的注解,那它自身就会完成注入,不需要再使用@EnableConfigurationProperties来开启了。
@Configurable(preConstruction = true)
告诉Spring在构造函数运行之前将依赖注入到对象中。假设 有这样一段代码: A a = new A(); 但A类中用了一些@Autowired 的类注入,这个时候你的a 类是无法正常创建的。但我们可以通过在A类上标注该注解,是的手动new出来的对象也可以使用依赖注入。