【问题标题】:Spring XML conf - join two params from jdbc.propertiesSpring XML conf - 加入来自 jdbc.properties 的两个参数
【发布时间】:2014-01-27 11:34:42
【问题描述】:

我想划分 JDBC URL 和 URL 参数。

在 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

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

但它不起作用。 有没有办法加入这两个参数?

【问题讨论】:

标签: java database spring jdbc


【解决方案1】:

假设您的应用程序中包含Spring Expression Language(第 8.4 节)模块,您应该能够使用以下内容:

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

作为url 属性的值。

【讨论】:

  • 如果我使用 "#{'${jdbc.url}' + '${jdbc.urlParams}'}" 编码不好。 有效,但我无法从 jdbc.properties 编辑参数:-(
  • 试试
  • pastebin.com/hFAFBPwX 表达式解析失败;嵌套异常是 org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'jdbc' cannot be found on type of 'org.springframework.beans.factory.config.BeanExpressionContext'
猜你喜欢
  • 2020-08-21
  • 1970-01-01
  • 2012-05-16
  • 2017-09-11
  • 2012-05-13
  • 2015-02-15
  • 2021-07-23
  • 2017-11-12
  • 1970-01-01
相关资源
最近更新 更多