属性配置汇总
- Devtools全局配置
- 测试@TestPropertySource注解
- 测试properties属性
- 命令行参数
- SPIRNG_APPLICATION_JSON属性
- ServletConfig初始化参数
- ServletContext初始化参数
- JNDI属性
- JAVA系统属性
- 操作系统环境变量
- RndValuePropertySource随机值属性
- jar包外的application-{profile}.properties
- jar包内的application-{profile}.properties
- jar包外的application.properties
- jar包内的application.properties
- @PropertySoruce绑定配置
- 默认属性
使用方法
在下面属性配置使用的demo中,需要测试配置的属性是否正确,测试的方法我用的是下面的下面的demo样例
- 获取属性工具类
@Component
public class SpringUtils implements ApplicationContextAware {
private ApplicationContext applicationContext;
@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}
/**
* 获取属性
*
* @param key
* @return
*/
public String get(String key) {
return applicationContext.getEnvironment().getProperty(key);
}
}
- 测试入口
@RestController
public class DemoController {