可以前往第一篇博客查看目录结构 --> 这里
一、自定义配置 (一些动态的数据:登录页面地址 、接收数据格式等等)
二、在core模块下创建properties目录 : com.zeke.core.properties 。在properties目录下创建SecurityProperties主配置文件,BrowserProperties浏览器配置文件,LoginType枚举类
LoginType :
public enum LoginType {
REDIRECT,
JSON
}
BrowserProperties :
public class BrowserProperties {
private String loginPage = "/zeke-login.html";
private LoginType loginType = LoginType.JSON;
public String getLoginPage() {
return loginPage;
}
public void setLoginPage(String loginPage) {
this.loginPage = loginPage;
}
public LoginType getLoginType() {
return loginType;
}
public void setLoginType(LoginType loginType) {
this.loginType = loginType;
}
}
SecurityProperties :
@ConfigurationProperties(prefix = "zeke.security")
public class SecurityProperties { private BrowserProperties browser = new BrowserProperties(); public BrowserProperties getBrowser() { return browser; } public void setBrowser(BrowserProperties browser) { this.browser = browser; }}三、在core模块 com.zeke.core 目录下添加SecurityCoreConfig类,使得SecurityProperties为配置类
@Configuration
@EnableConfigurationProperties(SecurityProperties.class)
public class SecurityCoreConfig {
}
四、这时候我们就可以在demo模块下的application.properties中配置我们需要的属性,例:(覆盖java文件中的loginPage属性)
zeke.security.browser.loginPage = /zeke-login.html
五、使用的时候@Autowired SecurityProperties securityProperties即可,示例:
@Autowired
private SecurityProperties securityProperties;
//使用
securityProperties.getBrowser().getLoginType()