1.新建文件“spring-configuration-metadata.json”
a.新建文件夹"META-INF"在"src/main/resources'下
b.新建文件“spring-configuration-metadata.json”在“META-INF”下
2.编辑文件“spring-configuration-metadata.json“
{
"hints": [],
"groups": [
{
"sourceType": "com.juling.config.Config",
"name": "juling",
"type": "com.juling.config.Config",
"description": "自定义配置"
}
],
"properties": [
{
"sourceType": "com.juling.config.Config",
"name": "juling.intercepturi",
"type": "java.util.List
"description": "强制拦截请求"
},
{
"sourceType": "com.juling.config.Config",
"name": "juling.releaseuri",
"type": "java.util.List
"description": "放行请求"
}
]
}
a.”com.juling.config.Config“为自定义的配置类路径
b.”juling“为application.yml第一层
c.”juling.intercepturi“为application.yml第二层
3.重新编译工程
4.编辑application.yml
juling:
intercepturi:
- /file/
releaseuri:
- /
- /manager/welcome
- /manager/login
这些都是可以自动提示的
5.编辑配置文件接收参数
package com.juling.config;
import java.util.List;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
@Component
@ConfigurationProperties(prefix = "juling")
public class Config {
public static List
public static List
public void setIntercepturi(List
Config.intercepturi = intercepturi;
}
public void setReleaseuri(List
Config.releaseuri = releaseuri;
}
}
a.我这里为了方便别的地方调用直接定义的为static,也可以不用定义为static
b.prefix = "juling"这个对应的是application.yml里的第一层juling
c.intercepturi,releaseuri这个就是第二层