Spring Boot自动配置

<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>

@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方法

@Configuration
@EnableConfigurationProperties(CheckWeakPasswordProperties.class)
@ConditionalOnProperty(prefix = "weak.password", name = "enabled", havingValue = "true")
public class CheckWeakPasswordAutoConfiguration {

public CheckWeakPasswordAutoConfiguration() {
}

@Bean
@ConditionalOnProperty(prefix = "weak.password", name = "checkType", havingValue = "2")
public CheckPasswordInterceptor checkPasswordInterceptor(){
return new CheckPasswordInterceptor();
}
@Bean
@ConditionalOnProperty(prefix = "weak.password", name = "checkType", havingValue = "2")
public CheckPasswordFilter checkPasswordFilter(){
return new CheckPasswordFilter();
}
@Bean
@ConditionalOnProperty(name = "weak.password.check-type", havingValue = "2")
public CheckPasswordFilterConfig checkPasswordFilterConfig() {
return new CheckPasswordFilterConfig();
}
@Bean
@ConditionalOnProperty(prefix = "weak.password", name = "checkType", havingValue = "1")
public CheckPasswordInterceptorConfig checkPasswordInterceptorConfig(){
return new CheckPasswordInterceptorConfig();
}

}

{
"groups": [
{
"name": "weak.password",
"type": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties"
}
],
"properties": [
{
"name": "weak.password.check-type",
"type": "java.lang.Integer",
"description": "拦截检查的方式 1-interceptor 2-filter 3-aop",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": 1
},
{
"name": "weak.password.check-uri",
"type": "java.lang.String[]",
"description": "需要检查的URI数组",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties"
},
{
"name": "weak.password.client-name",
"type": "java.lang.String",
"description": "客户端名称",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": "cloud-user"
},
{
"name": "weak.password.enabled",
"type": "java.lang.Boolean",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": true
},
{
"name": "weak.password.failure-message",
"type": "java.lang.String",
"description": "校验失败信息提示",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": "密码等级不够"
},
{
"name": "weak.password.ip",
"type": "java.lang.String",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": "127.0.0.1"
},
{
"name": "weak.password.port",
"type": "java.lang.String",
"sourceType": "com.yunchuang.password.properties.CheckWeakPasswordProperties",
"defaultValue": "8501"
}
],
"hints": []
}

Spring Boot自动配置

上一篇:c++ 11 目录流DIR,dirent使用


下一篇:adb命令 【Android 调试桥】