SpringBoot 使用技巧与心得

时间:2020-07-24 13:24:29   收藏:0   阅读:85

 

 

1. 配置类有3次机会可以去覆盖配置,这对于框架封装是很有好处的

 1 // 2. 在 bean 生成后,populateBean() 时,在 application.yml 配置文件里面进行覆盖
 2 @ConfigurationProperties(prefix = "cas")
 3 public class CasConfiguration implements InitializingBean {
 4     private String casServerUrl;
 5     
 6     @Override
 7     public void afterPropertiesSet() throws Exception {
 8         // 3. 在生成了 bean 之后,populateBean() 之后,还有一次机会进行配置覆盖
 9         ...
10     }
11 }
12 
13 
14 使用 BeanMethod 的方式定义 bean 的时候,可以对配置进行第一次覆盖
15 @Bean
16 public CasConfiguration casConfiguration(){
17     CasConfiguration cas = new CasConfiguration();
18     // 1. 在 bean 生成之前进行配置初始化
19     ...
20     return cas;
21 }

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!