springmvc中怎么从配置文件中读取信息
1个回答
2014-12-28
展开全部
springmvc中如何从配置文件中读取信息
<!-- 系统配置参数. --> <bean value="true" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="location" value="classpath:/fynetAdminSettings/app.properties" /> </bean> <bean id="sysUsersConfigBean" name="code">package com.fyard.fynet.core.settings.admin;import java.util.HashMap;import java.util.Map;import org.springframework.stereotype.Component;/** * 系统用户对象 * */@Componentpublic class SysUsersConfigBean { private Map<String, String> sysUserInfo = new HashMap<String, String>(); public Map<String, String> getSysUserInfo() { return sysUserInfo; } public void setSysUserInfo(Map<String, String> sysUserInfo) { this.sysUserInfo = sysUserInfo; } public String getPassword(String username) { return sysUserInfo.get(username); }}
以上三步就可以直接读取配置文件中的数据,.properties文件中的值会自动映射到xml文件中的bean中,SysUsersConfigBean该类已经被标注为@Component,在service层就可以直接调用即可
<!-- 系统配置参数. --> <bean value="true" /> <property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" /> <property name="location" value="classpath:/fynetAdminSettings/app.properties" /> </bean> <bean id="sysUsersConfigBean" name="code">package com.fyard.fynet.core.settings.admin;import java.util.HashMap;import java.util.Map;import org.springframework.stereotype.Component;/** * 系统用户对象 * */@Componentpublic class SysUsersConfigBean { private Map<String, String> sysUserInfo = new HashMap<String, String>(); public Map<String, String> getSysUserInfo() { return sysUserInfo; } public void setSysUserInfo(Map<String, String> sysUserInfo) { this.sysUserInfo = sysUserInfo; } public String getPassword(String username) { return sysUserInfo.get(username); }}
以上三步就可以直接读取配置文件中的数据,.properties文件中的值会自动映射到xml文件中的bean中,SysUsersConfigBean该类已经被标注为@Component,在service层就可以直接调用即可
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询