在spring boot中使用自定义的properties
1 在application.properties中添加
android.name=Tim
android.password=123456
新建一个保存该Setting的配置类,
@ConfigurationProperties(prefix="android")
public class AndroidSettings {
private String name;
private String password;
//setters and getters
......
}
2 在自己的properties文件中添加
android.name=Tim
android.password=123456
@Component
@PropertySource("classpath:config/android.properties")
@ConfigurationProperties(prefix="android")
public class AndroidSettings {
private String name;
private String password;
//setters and getters
......
}
3 这两种方式都要在Spring boot的入口类上加上@EnableConfigurationProperties
@SpringBootApplication
@EnableConfigurationProperties(AndroidSettings.class)
public class DemoApplication {
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}
4 使用定义的properties
@AutoWired
AndroidSettings androidSettings;
最新文章
- android开发:深入理解View(一):从setContentView谈起
- BZOJ2498 : Xavier is Learning to Count
- AWK命令的用法
- 电子词典的相关子函数db.c程序
- [转载]有了 malloc/free 为什么还要 new/delete ?
- Umbraco Form需要引用些客户端dependencies (jquery)
- 动态的 css——less
- ecshop标签大全 各个页面常用标签大全
- Modbus通信协议详解
- vue webuploader 组件开发
- web@css高级选择器(after,befor用法),基本css样式
- Python学习之MacBook Pro中PyCharm安装pip以及itchat
- mybatis动态排序
- 获取本机IP地址的小脚本
- Intellij idea 2017 图标含义
- three.js学习:点光源+动画的实现
- TLabel的FocusControl属性什麽意思
- 配置mysql主从数据库
- 核心API的使用(获取两个字符串的最大相同子串)
- org.apache.commons.lang.StringUtils