2014-01-27 18 views
0

我想劃分JDBC URL和URL參數。Spring XML conf - 從jdbc.properties連接兩個參數

在jdbc.properties我:

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 

春天xml配置:

<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> 

但它不工作。 有什麼方法可以加入這兩個參數?

+0

可能重複的[連接字符串在一個Spring XML配置文件?](http://stackoverflow.com/questions/4261372/concatenate-strings-within-a-spring-xml-configuration-file) – nobeh

回答

0

假設您已經包含在你的應用程序Spring Expression Language(8.4節)模塊,你應該能夠使用以下命令:

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

url屬性的值。

+0

如果我使用「#{'$ {jdbc.url}'+'$ {jdbc.urlParams}'}」編碼不好。 有效,但我無法從jdbc.properties編輯params :-( – martin

+0

try < property name =「url」value =「#{jdbc.url + jdbc.urlParams}」/> –

+0

http://pastebin.com/hFAFBPwX表達式解析失敗;嵌套異常是org.springframework.expression.spel.SpelEvaluationException:EL1008E :(pos 0):無法在'org.springframework.beans.factory.config.BeanExpressionContext'類型的對象上找到字段或屬性'jdbc' – martin