1.显示配置进行覆盖
SpringSecurity引入后,编写一个显示的配置即可覆盖。
原理:SpringBoot先加载应用级别配置。随后加载自动配置。自动配置上回通过条件注解看是否已经有相关注解,如果有了,就不在进行自动配置。
2. 通过属性文件外置配置
可能是命令行参数,yaml文件,properties文件。
通过yaml文件可以调整很多配置,如:端口,数据源,日志级别,模板缓存。
3. 应用程序Bean的配置外置
@Data
@Component
@ConfigurationProperties("amazon")
public class Amazon {
private String associateId;
}
4. 使用Profile进行配置
1.用法
可以根据环境进行适当的注入,如下只有dev环境才会生效
@Profile("dev")
@RestController
@AllArgsConstructor
@RequestMapping("/amazon")
public class AmazonController {
private Amazon amazon;
@GetMapping("/readYaml")
public String readYaml(){
return amazon.getAssociateId();
}
}
2.设置值
- 通过命令设置,–spring.profiles.active=production
- 通过yaml文件设置
- 使用不同的文件区分
- 使用多Profile YAML文件进行配置,通过一组三个连字符(—)进行分割
5. 定制应用程序错误页面
在templates下编写error.html文件。