Spring 导入配置文件的两种方式
来源:互联网 发布:linux i have no name 编辑:程序博客网 时间:2024/06/05 17:24
1.在Spring配置文件中引入properties文件
在application.xml中添加
xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
scheme
然后通过
<context:property-placeholderlocation="db.properties"></context:property-placeholder>
引入配置文件。
2.读取配置文件,生成properties对象,并注入至IOC容器
在application.xml中添加
xmlns:util="http://www.springframework.org/schema/util"
http://www.springframework.org/schema/utilhttp://www.springframework.org/schema/util/spring-util-4.1.xsd
scheme 注意版本区分
然后通过
<util:propertiesid="commonProps"location="classpath:"local-override="true"/>
注入到ico容器中。
在使用@Value 注解获取到属性值
@Value("#{sys.test}")
private String test;
@Value("#{sys.test}")
public void setTest(String test){
test = test;
}
@Value("#{sys}")
public void setSysConf(Properties sys){
test= sys.getProperty("test");
}
阅读全文
0 0
- Spring 导入配置文件的两种方式
- Spring加载配置文件的两种方式
- spring读取配置文件的两种方式
- spring 整合hibernate的配置文件的两种方式
- Spring配置文件applicationContext.xml的两种拆分方式
- Spring-boot中读取config配置文件的两种方式
- Spring配置文件applicationContext.xml的两种拆分方式
- Spring-boot中读取config配置文件的两种方式
- Spring学习-03:ApplicationContext加载配置文件的两种方式
- Spring-boot中读取config配置文件的两种方式
- Spring-boot中读取config配置文件的两种方式
- Spring-boot中读取config配置文件的两种方式
- spring+hibernate 两种整合方式配置文件
- spring+hibernate 两种整合方式配置文件
- spring+hibernate 两种整合方式配置文件
- 两种解析properties配置文件的方式
- hibernate加载配置文件的两种方式
- spring 引入数据库配置(其他配置文件.properties)文件的两种方式
- zookeeper整合kafka
- struts中无法通过直接访问到根目录
- 触发器的介绍及MySQL触发器的简单例子
- css字体大小兼容性问题
- Badboy自动化测试工具9 查看回放结果
- Spring 导入配置文件的两种方式
- Linux 文件系统类型
- Android——UI篇:ViewPager轮播图控制滑动速度
- error: Your local changes to the following files would be overwritten by merge:
- Oracle创建,添加,修改,删除
- 复杂链表的复制及测试
- Golang基础语法(一)
- 聚类
- 前端基础常见问题