您的位置:首页 > 移动开发

(六)、SpringBoot 自定义配置属性,可以在application.properties中修改

2018-03-14 10:51 871 查看
可以前往第一篇博客查看目录结构 --> 这里

一、自定义配置 (一些动态的数据:登录页面地址 、接收数据格式等等)
二、在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()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  sringboot 配置属性
相关文章推荐