springboot的注解详解

配置类相关:

@PropertySource(value = "classpath:test.properties")   //我们都把配置文件写到application.yml中。有时我们不愿意把配置都写到application配置文件中,这时需要我们自定义配置文件,比如test.properties:

@ConfigurationProperties(prefix = "com.forezp")         //在配置文件中的前缀,属性自动注入

@EnableConfigurationProperties      //@ConfigurationProperties注解主要用来把properties配置文件转化为bean来使用的,而@EnableConfigurationProperties注解的作用是@ConfigurationProperties注解生效。如果只配置@ConfigurationProperties注解,在IOC容器中是获取不到properties配置文件转化的bean的。一般不用加,因为在我们的的appliacation的启动类@SpringBootApplication注解中已经包含了@ComponentScan和@EnableConfigurationProperties注解。

猜你喜欢

转载自www.cnblogs.com/coder-lzh/p/8983857.html
今日推荐