Following is my tomcat context.xml
<Parameter name="datasource.url" override="false" value="jdbc:mysql://localhost:3306/"/>
<Parameter name="datasource.username" override="false" value="root"/>
<Parameter name="datasource.password" override="false" value="password"/>
I want to read these property values into spring xml using PropertyPlaceHolderConfigurer to replace the values in following code for datasource.username, datasource.password,datasource.url
<beans:bean id="dataSource" destroy-method="close"
class="com.mchange.v2.c3p0.ComboPooledDataSource">
<beans:property name="driverClass" value="com.mysql.jdbc.Driver" />
<beans:property name="jdbcUrl"
value="${datasource.url:jdbc:mysql://localhost:3306/exampledb}" />
<beans:property name="user" value="${datasource.username:root}" />
<beans:property name="password" value="${datasource.password:root}" />
</beans:bean>
my propertyHolder configuration
<beans:bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<beans:property name="nullValue" value="@null" />
<beans:property name="systemPropertiesModeName" value="SYSTEM_PROPERTIES_MODE_OVERRIDE"/>
<beans:property name="locations">
<beans:list>
<beans:value>classpath:mysql-queries.properties</beans:value>
<beans:value>classpath:essayscoring-settings.properties
</beans:value>
</beans:list>
</beans:property>
</beans:bean>
please suggest me how to read those values from tomcat context.xml into propertyPlaceHolder
Spring approach is correct one. Create a separate properties file and import in spring:
<context:property-placeholder location="classpath*:some.properties"/>
then import spring context into your tomcat context:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.