1、配置Maven依赖
Spring Boot自动化配置主要依赖如下两个包:
- spring-boot-starter:打包starter主要依赖
- configuration-processor:自动化配置主要依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
2、创建实体类映射配置信息
众所周知,SpringBoot Starter最厉害的就是可以通过最简单的properties/yaml文件配置,达到最终目的。配置文件需要通过解析生成对应的实体类
@ConfigurationProperties(prefix = "weak.password") public class CheckWeakPasswordProperties { private Boolean enabled = true; /** * 需要检查的URI数组 */ private String[] checkUri; /** * 拦截检查的方式 1-interceptor 2-filter 3-aop */ private Integer checkType = 1; private String ip = "127.0.0.1"; private String port = "8501"; /** * 客户端名称 */ private String clientName = "cloud-user"; /** * 校验失败信息提示 */ private String failureMessage = "密码等级不够"; ...// 省略getter/setter方法
https://www.cnblogs.com/jian0110/p/15152884.html