I am using Spring Jdbc template and for that I have context.xml
我正在使用Spring Jdbc模板,因为我有context.xml
<property name="driverClassName" value="com.informix.jdbc.IfxDriver" />
<property name="url"
value="jdbc:informix-sqli://testdb:1111/dddd:informixserver=linuxdev" />
<property name="username" value="test" />
<property name="password" value="test" />
</bean>
As I have hard coded the values like "driverClassName" instead I want to load them from a properties file like ${test.driverName} .
因为我已经对像“driverClassName”这样的值进行了硬编码,所以我想从$ {test.driverName}这样的属性文件中加载它们。
Does any one know how can I do this one ?
有谁知道我该怎么做?
1 个解决方案
#1
1
In Spring 3 you can set property-placeholder location and use ${key} notation right away:
在Spring 3中,您可以设置property-placeholder位置并立即使用$ {key}表示法:
<context:property-placeholder location="classpath:config.properties"/>
In Spring 2 (I think) you will need to introduce a propertyConfigurer bean like that:
在Spring 2中(我认为)你需要引入一个propertyConfigurer bean:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>
#1
1
In Spring 3 you can set property-placeholder location and use ${key} notation right away:
在Spring 3中,您可以设置property-placeholder位置并立即使用$ {key}表示法:
<context:property-placeholder location="classpath:config.properties"/>
In Spring 2 (I think) you will need to introduce a propertyConfigurer bean like that:
在Spring 2中(我认为)你需要引入一个propertyConfigurer bean:
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>classpath:config.properties</value>
</list>
</property>
</bean>