(六)、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;
一、自定义配置 (一些动态的数据:登录页面地址 、接收数据格式等等)
二、在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()
相关文章推荐
- spring boot-application.properties配置文件属性
- SpringBoot属性文件配置(application.properties/yml)
- Appendix A. Spring boot 配置属性大全,史上最全application.properties--张振华.Jack
- Springboot属性文件application.properties配置大全,版本:1.5.4
- Spring boot 学习笔记(1)——hello world创建,属性application.properties、 yml配置
- SpringBoot属性配置实战(application.properties)
- Spring Boot为我们准备了最佳的数据库连接池方案,只需要在属性文件(例如application.properties)中配置需要的连接池参数即可。
- springboot 修改默认加载的配置文件不为application.properties
- spring boot application.properties 全部配置属性
- 【spring boot】配置文件 application.properties 属性解析
- SpringBoot内部配置:“application.properties配置”和”使用XML配置”,读取属性文件中的内容,日志配置,Profile配置(学习:SpringBoot实战)
- 如何将spring boot application.properties修改成为spring boot配置文件
- Spring-boot中读取核心配置文件application和自定义properties配置文件的方式
- Spring Boot属性文件application.properties配置文档(全部)
- spring-boot application.properties配置文件和自定义配置文件
- springboot 修改启动时默认加载application.properties文件以及加载指定配置文件
- ApplicationContextAware获取Spring上下文,通过基类获取properties中的配置属性
- springboot的application.properties配置文件的配置项读取
- SpringBoot中自定义properties文件配置参数并带有输入提示
- spring boot 使用application.properties 进行外部配置