使用spring注解方法读取properties文件中值
来源:互联网 发布:linux创建用户加入组 编辑:程序博客网 时间:2024/05/22 10:40
引用properties还是要在xml里配置,有两种配置方法,对引用单个properties文件,和多个properties文件
一、读取单个 properties 文件
在 spring 的配置文件中,加入
引入until命名空间:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
读取properties文件
<util:properties id="propertiesReader" location="classpath:test.properties" />
二、读取多个 properties 文件
<bean id="propertiesReader"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:param.properties</value>
<value>classpath:base.properties</value>
</list>
</property>
</bean>
一、读取单个 properties 文件
在 spring 的配置文件中,加入
引入until命名空间:
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.0.xsd"
读取properties文件
<util:properties id="propertiesReader" location="classpath:test.properties" />
二、读取多个 properties 文件
<bean id="propertiesReader"
class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath:param.properties</value>
<value>classpath:base.properties</value>
</list>
</property>
</bean>
两种方法其实都是一样的
在类中读取properties文件属性
在类中需要注入的属性实现 setter 和 getter 方法。
在 setter 方法前,添加 @Value 注解
@Value("#{propertiesReader[propertiesName]}")
propertiesName 为 properties 文件中的键。这样,在容器启动过程中, Spring 将自动注入值。
2 6
- 使用spring注解方法读取properties文件中值
- 使用spring注解方法读取properties文件中值
- spring注解方式读取properties文件中值
- spring使用注解@Value读取.properties文件
- 使用spring读取properties文件
- spring注解中使用properties文件
- spring注解的方式读取properties文件中的内容
- Spring使用程序方式读取properties文件
- Spring使用程序方式读取properties文件
- Spring 使用@PropertySource读取properties文件
- 使用Spring PropertiesLoaderUtils读取properties属性文件
- Spring 使用@PropertySource+Emvironment读取properties文件
- Spring 读取 properties文件
- Spring 读取properties文件
- spring读取properties文件
- spring 读取properties文件
- spring读取properties文件
- spring读取properties文件
- C#获取web.config配置文件内容
- QT学习笔记之Qdialog
- HDU 1800 Flying to the Mars (贪心)
- 用git发patch
- ios开发学习笔记
- 使用spring注解方法读取properties文件中值
- C++之异常处理
- 利用GetPrivateProfileString读取配置文件(.ini)
- Xcode 4.4中LLVM compiler 4.0带来的Objective-C新语法特性
- OpenStack Heat总结之:icehouse版本中Heat的简单介绍
- 张默吸毒再被抓
- 8大最有气质的网络公司
- [android引用他人包出现的错误]All versions of the libraries must be the same at this time.以及It is indirectly re
- Android 百度地图开发问题----解决地图有时候加载不出来问题