<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:application.properties
</value>
<value>classpath:resource.properties
</value>
</list>
</property>
</bean>
比如我在resource.properties里面定义了一些配置信息,那么我如何在spring里面得到这个信息呢?
是一个web环境。不是main方式说动加载。
我实例化PropertyPlaceholderConfigurer和它的父类,都没有相应的方法可以获取到。不知道如何做
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE" />
<property name="ignoreResourceNotFound" value="true" />
<property name="ignoreUnresolvablePlaceholders" value="true" />
<property name="locations">
<list>
<value>classpath:application.properties
</value>
<value>classpath:resource.properties
</value>
</list>
</property>
</bean>
比如我在resource.properties里面定义了一些配置信息,那么我如何在spring里面得到这个信息呢?
是一个web环境。不是main方式说动加载。
我实例化PropertyPlaceholderConfigurer和它的父类,都没有相应的方法可以获取到。不知道如何做
解决方案 »
- 有意思的继承关系的面试陷阱题,进来学习一下吧~~
- 如何获取某台计算机Mac Address ?
- 这么多天了,到底哪位大哥可以帮助我呀,谢谢了!
- ArrayList合并的问题!!
- 菜鸟问体:我的Applet无法正常显示的愿意
- 一个基础的问题
- 如何让程序休眠.。。。。。。。。。。。
- 为什么 java.sql.SQLException: [Microsoft][ODBC SQL Server Driver]没有执行可选特性
- 请教:如何从string中提取int值
- 为什么有很多问题明明有人给了很好的回答,但是提问的人不给分,说明这些人心态有问题?
- installanywhere 生成好的应用程序用不了
- JTree的问题 求高手来解决
import java.io.FileInputStream;
import java.util.Properties;
public class TestProperties {
public static void main(String[] args) {
Properties props = new Properties();
String name_en = "",password_en = "",name_cn = "",password_cn = "";
try{
props.load(new FileInputStream(new TestProperties().getClassDirectory()+"test.properties"));
name_en = props.getProperty("name_en");
password_en = props.getProperty("password_en");
name_cn = props.getProperty("name_cn");
password_cn = props.getProperty("password_cn");
}catch(Exception e){
e.printStackTrace();
}
System.out.println("name_en = "+name_en+" , password_en = "+password_en);
System.out.println("name_cn = "+name_cn+" , password_cn = "+password_cn);
}
String getClassDirectory() {
String cla = this.getClass().getClassLoader().getResource(".").getPath();
return cla;
}
}
哪位知道告诉一下。