简体   繁体   中英

Spring XML conf - join two params from jdbc.properties

I want to divide JDBC URL and URL params.

In jdbc.properties I have:

jdbc.driverClassName=com.mysql.jdbc.Driver
jdbc.url=jdbc:mysql://db.server.tld:3306/dbName
jdbc.username=user
jdbc.password=pass
jdbc.urlParams=?useUnicode=true&characterEncoding=utf-8

In spring xml config:

<bean id="propertyConfigurer"
    class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="location"><value>classpath:jdbc.properties</value></property>
</bean>
<bean id="dataSource"
    class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    <property name="driverClassName" value="${jdbc.driverClassName}" />
    <property name="url" value="${jdbc.url}${jdbc.urlParams}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
</bean>

But it doesn't work. Is there any way to join these two params?

Assuming that you have included Spring Expression Language (section 8.4) module with your application, you should be able to use the following:

#{'${jdbc.url}' + '${jdbc.urlParams}'}

as the value for url property.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM