简体   繁体   English

Spring XML conf-从jdbc.properties连接两个参数

[英]Spring XML conf - join two params from jdbc.properties

I want to divide JDBC URL and URL params. 我想划分JDBC URL和URL参数。

In jdbc.properties I have: 在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

In spring xml config: 在spring 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>

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: 假设您在应用程序中包括了Spring Expression Language (第8.4节)模块,则您应该能够使用以下内容:

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

as the value for url property. 作为url属性的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用context.xml更改jdbc.properties - Change jdbc.properties with context.xml 部署之后,Spring不再找到.Jar之外的JDBC.Properties - After deployment JDBC.Properties outside .Jar not found by Spring anymore appfuse配置jdbc.properties - appfuse configuring jdbc.properties 为mybatis定义了“jdbc.properties”,但仍需要在application.properties中添加spring.datasource? - defined “jdbc.properties” for mybatis, but still need add spring.datasource in application.properties? 切换到Java 1.8-Spring 4后无法打开ServletContext资源[/jdbc.properties] - Could not open ServletContext resource [/jdbc.properties] after switch to Java 1.8-Spring 4 使用classpath:resources / jdbc.properties加载属性文件 - load property file using classpath:resources/jdbc.properties 动态更改jdbc.properties和log4j.properties的文件目录 - Dynamic Change of files directory for jdbc.properties and log4j.properties 无法打开类路径资源[target / jdbc.properties],因为它不存在 - class path resource [target/jdbc.properties] cannot be opened because it does not exist 无法打开类路径资源[default / jdbc.properties],因为它不存在 - class path resource [default/jdbc.properties] cannot be opened because it does not exist 弹簧与kotlin预定注释从属性文件获取参数 - spring with kotlin scheduled annotation getting params from properties file
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM