[英]Using properties file inside the xml
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 ? 有谁知道我该怎么做吗?
In Spring 3 you can set property-placeholder location and use ${key} notation right away: 在Spring 3中,您可以设置属性占位符的位置并立即使用$ {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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.