@ConfigurationProperties()与@Value

1.@ConfigurationProperties()需要@EnableConfigurationProperties(ConnectionProperties.class)一起使用。

2.@ConfigurationProperties("yc.conn"):将配置文件中的yc.conn属性与加了这个注解的Bean的属性绑定

3.@EnableConfigurationProperties(ConnectionProperties.class):让使用了 @ConfigurationProperties 注解的类生效, 并且将该类注入到 IOC 容器中,交由 IOC 容器进行管理

4.@ConfigurationProperties()常用于属性配置很多的情况

5.@Value:写在属性上,读取配置文件到属性上,用于配置项少的情况

猜你喜欢

转载自blog.csdn.net/qq_59384418/article/details/129472950