我正在使用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>
由于我对“driverClassName”这样的值进行了硬编码,我想从$ {test.driverName}这样的属性文件中加载它们。
有谁知道我该怎么做?
答案 0 :(得分:1)
在Spring 3中,您可以设置property-placeholder位置并立即使用$ {key}表示法:
<context:property-placeholder location="classpath:config.properties"/>
在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>