Spring中读取配置文件信息
来源:互联网 发布:unity3d动画制作教程 编辑:程序博客网 时间:2024/05/24 07:44
Spring中后台读取配置文件信息
有些配置信息,不同的环境,配置信息不同,需要在后端使用这些信息,使用Spring3支持的@value注解的方式获取properties文件中的配置值,大大简化了读取配置文件的代码。
步骤:
- 在applicationContext.xml(spring的配置文件,不要加入到springmvc的配置文件中)文件中配置properties文件
<bean id="configProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean"> <property name="locations"> <list> <value>classpath:conf/main-setting-web.properties</value> </list> </property> </bean>
2.main-setting-web.properties文件中增加参数
auth.server.url=$[authServerUrl]server.name=$[serverName]
authServerUrl,serverName是在maven中配置的
3.controller中使用
@Value("#{configProperties['auth.server.url']}") private String authServerUrl; @Value("#{configProperties['server.name']}") private String serverName;
configProperties为applicationContext.xml中配置的bean id
0 0
- Spring中读取配置文件信息
- spring框架读取配置文件信息
- Spring无法读取配置文件信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 如何在spring中读取properties配置文件里面的信息
- 自定义类在spring中读取properties配置文件信息
- 通过Spring读取properties配置文件的信息 Spring 读取properties
- Spring -- 如何在spring中读取properties配置文件里面的信息
- 在spring中读取properties配置文件
- spring配置文件中读取外部参数
- spring中读取数据库的property配置文件
- spring中如何读取.properties配置文件
- spring中读取配置文件的参数
- Spring类中获取配置文件信息
- JavaScript 限制文本框不可输入英文单双引号
- C语言 - 比较部分字符串函数的使用
- Redis入门
- Activity返回(finish)时,另一个activity或者fragment如何刷新数据
- 使用Apache commons-net包的ftp时中文文件名乱码的问题
- Spring中读取配置文件信息
- 欢迎使用CSDN-markdown编辑器
- Visual Stdio 配置 MySql 数据库
- dependencies与dependencyManagement的区别
- loadrunner中变量转换成一个参数
- C++学习笔记-----存在多态调用时,为基类定义虚析构函数
- 从微信WeUI设计规范 解读移动界面设计
- 移动端的数据滚动插件
- WiFi客流统计可以为哪些岗位提供市场洞察?