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 }

![SpringBoot 使用技巧与心得
[编程语言教程]](https://www.zixueka.com/wp-content/uploads/2024/01/1706716457-28854fea55e04d6.jpg)
