博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
SpringBoot慕课学习-SpringBoot开发常用技术整合-资源文件属性配置
阅读量:6892 次
发布时间:2019-06-27

本文共 665 字,大约阅读时间需要 2 分钟。

作用:资源文件中的配置属性映射到实体类属性

1.引入包

org.springframework.boot
spring-boot-configuration-processor

2. 创建一个properties文件resource.properties

opensource.name=helloopensource.website=imooc.comopensource.language=java

3. 创建Resource.java

//@Configuration 声明使用配置文件@Configuration@ConfigurationProperties(prefix="opensource")@PropertySource(value="classpath:resource.properties")public class Resource {    private String name;    private String website;    private String language;//getter.setter}

4. 需要使用的地方使用 自动装配

@Autowired

private Resource resource;

 

转载于:https://www.cnblogs.com/bigorang/p/9591234.html

你可能感兴趣的文章
MetaMask/metamask-extension/mascara 的运行实现
查看>>
loglevel-metamask
查看>>
决策树算法实现(train+test,matlab) 转
查看>>
51Nod-1126 求递推序列的第N项【递推序列+模除】
查看>>
Eratosthenes筛选法(C++版)
查看>>
HDU1163 Eddy's digital Roots
查看>>
Topological Sorting(拓扑排序)
查看>>
css学习_css用户界面样式
查看>>
Optisystem中绝对码变相对码
查看>>
时间格式处理
查看>>
【转】android windowSoftInputMode
查看>>
php Socket通信
查看>>
[周年感悟]看软件项目中的四种角色
查看>>
eclipse tomcat7.0 start 常见错误警告
查看>>
chrome浏览器
查看>>
【转】iOS库 .a与.framework区别
查看>>
java多线程编程之使用Synchronized块同步方法
查看>>
第二十八天笔记
查看>>
C# Lock
查看>>
CentOS-6.8 安装zabbix 4.0X
查看>>