Spring MVC 通过@Value注解读取.properties配置内容
2016-01-13 10:08
627 查看
第一步:在applicationContext.xml配置:
第二步:
建立配置文件内容:
例如:userPageSize=5
第三步:
在Controller中使用注解获得配置项内容:
<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中使用注解获得配置项内容:
@Value("#{configProperties['userPageSize']}") private String userPageSize; getter setter
相关文章推荐
- eclipse中快捷键
- Java内存溢出详解
- hibernate的配置1
- JAVA线程同步辅助类CountDownLatch
- java 提取目录下所有子目录的文件到指定位置
- 深入浅出RxJava(一:基础篇)
- 国外用spring开发的开源系统值得学习
- eclipse Debug 技巧
- java 线程
- Eclipse中如何添加Junit jar包
- Myeclipse中快捷键大全
- Java使用“==”所遇到的坑
- java中静态代码块的使用场景
- Spring框架的使用
- 把Eclipse自带的浏览器修改为自己习惯的浏览器
- 修改Eclipse格式化代默认长度
- Struts2配置
- Java多态性
- java使用DOM操作XML
- Spring Boot JPA 连接数据库