SpringBoot 使用技巧与心得


	SpringBoot 使用技巧与心得
[编程语言教程]

 

 

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 }
hmoban主题是根据ripro二开的主题,极致后台体验,无插件,集成会员系统
自学咖网 » SpringBoot 使用技巧与心得