Spring-boot 第三方配置
Bean的注入从配置文件中来
方法1,使用EnableConfigurationProperties注解
在App的类上加上EnableConfigurationProperties如:
1 | |
需要注入的bean加入@ConfigurationProperties(prefix = "foo")注解。
1 | |
application.properies中,以增加以前缀开头的配置+字段名为key的键值对。
1 | |
使用:直接用@Autowired注解。
1 | |
方法2,@Bean及@ConfigurationProperties
在App类中增加方法
1 | |
其它配置如上
这种方法ConfigBean上无需ConfigurationProperties配置
参考
Spring-boot 第三方配置
https://blog.fengcl.com/2017/11/28/spring-boot-configurationproperties/