Spring MVC 通过@Value注解读取.properties配置内容
2016-04-28 13:11
471 查看
1 @Value("#{configProperties['userPageSize']}") 2 private String userPageSize;
第一步:
在applicationContext.xml配置:
<bean id="configProperties"class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:/config/*.properties</value> </list> </property> </bean> <bean id="propertyConfigurer"class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"> <property name="properties"ref="configProperties"/> </bean>
第二步:
建立配置文件内容:
例如:userPageSize=5
第三步:
在Controller中使用注解获得配置项内容:
1 @Value("#{configProperties['userPageSize']}") 2 private String userPageSize;
第四步:
后面的代码就可以使用userPageSize这个私有变量了,这个字符串的值就是我们配置文件中配置的5.
http://www.thinksaas.cn/topics/0/201/201007.html
相关文章推荐
- 解决SpringMVC传输json数据时的乱码
- Java---IO加强(3)-IO流的操作规律
- Java---IO加强(3)-IO流的操作规律
- spring mvc 无法扫描jar中controller和Service
- java keylistener 问题
- jar打包.class文件
- Scanner、String(java基础知识十二)
- 初学java集合-map—API
- 一个有意思的 Java HashSet 问题
- java中关于容器的描述
- Eclipse断点调试
- [1.1]第一个Spark应用程序之Java & Scala版 Word Count
- java学习第一步 sublime环境配置
- office转pdf(在线预览)思路(java示例)
- Spring入门之bean的属性
- java GC机制的一些总结
- Java报文或者同步的数据有个别乱码情况的处理.
- eclipse远程连接hbase错误
- RxJava----操作符:组合操作符
- 【java】获取一年里某季、某月、某周的第一天及最后一天时间(日期工具类)