spring注解中使用properties文件
来源:互联网 发布:欧洲看不起美国知乎 编辑:程序博客网 时间:2024/05/01 04:22
from:http://dearhappyfish.blog.163.com/blog/static/190109415201376111925653/
一、只读取单个 properties 文件
1、在 spring 的配置文件中,加入
引入命名空间:
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"
内容中写入
<util:properties id="propertiesReader" location="classpath:test.properties" />
2、在类中需要注入的属性实现 setter 和 getter 方法。
3、在 setter 方法前,添加 @Value 注解
@Value("#{propertiesReader[propertiesName]}")
propertiesName 为 properties 文件中的键。这样,在容器启动过程中, Spring 将自动注入值。
二、读取多个 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>
0 0
- spring注解中使用properties文件
- spring使用注解@Value读取.properties文件
- Spring中加载 .properties 文件在java注解中使用及xml的el表达式使用
- 使用spring注解方法读取properties文件中值
- 使用spring注解方法读取properties文件中值
- 使用Spring注解方式注入properties文件乱码解决
- 在Spring配置文件中使用properties文件
- Spring 通过注解注入Properties文件
- spring注解方式读取properties文件中值
- spring 使用注解获取properties 文件属性值
- 如何在spring中使用properties文件中属性
- Spring 中引用Properties文件
- spring中加载properties文件
- Spring中引入properties文件
- Spring中引入properties文件
- 使用spring读取properties文件
- Spring中属性文件properties的读取与使用
- Spring中属性文件properties的读取与使用
- WinCE 程序打包CAB
- 数字电路设计之ARM m0进度(2)
- 数据库解析——mysql explain 详解
- 如何在Root的手机上开启ViewServer,使得HierachyViewer能够连接
- lua require dofile loadfile区别
- spring注解中使用properties文件
- RadioButton 单选按钮组
- Win7 64位系统,VS2010环境下编译cuda-convnet指南
- ubuntu环境下查看系统是32位还是64位
- spring 3中新增的@value注解
- ios 保存数据NSKeyedArchiver,NSUserDefaults,Write,SQLite
- zoj 3538 Arrange the Schedule[矩阵]
- jQuery与Java实现图片的剪切
- Windows文件名长度限制