struts2配置文件有没有类似spring配置文件引用properties的功能
如:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
如:
<bean id="placeholderConfig"
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="location">
<value>classpath:init.properties</value>
</property>
</bean>
解决方案 »
- lili830209 D调的河马 进来接分。。。。
- 如何使用jms作为通讯机制实现glassfish集群
- jsp 页面表格Excel导出 “automation服务器不能创建对象”错误
- ognl表达式
- 关于用servlet大家帮帮忙
- 小弟出来次地,有一个棘手的问题,有会用JAVA编写DFT和FFT的高人吗?
- 关于cmp的问题,环境jbuilder9,jboss3.22(进者有分,倾家荡产也得把这问题搞懂)
- 有关JDK的问题
- spring 自定义annotation
- shiro spring springmvc整合异常
- 研究在输入页面信息时未点保存就点其他菜单时弹出提示信息的问题
- 类型不匹配,已经进行了强制类型转化,怎么回事
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import java.util.Map.Entry;/**
* 读取properties配置文件
*/
public class PropertiesUtil { private static Properties props = null;
/**
* 根据KEY查询prop文件的值
* @param key
* @param propFileName prop 文件名 文件位于classes目录中
*/
public static Object getValueByKeyFormProp(String key, String propFileName)throws IOException{
props = new Properties();
props.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(propFileName));
return props.get(key);
}
/**
* 将prop转化成Map
*/
public static Map<String, String> propToMap(String propFileName)throws IOException{
Map<String, String> map = new HashMap<String, String>();
props = new Properties();
props.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(propFileName));
for(Entry<Object, Object> entry : props.entrySet()){
map.put(entry.getKey().toString(), entry.getValue().toString());
}
return map;
}
public static void main(String[] args) throws Exception{ System.out.print(PropertiesUtil.getValueByKeyFormProp("49", "memberlevel.properties"));
}}