【问题标题】:CrafterCMS: How to use crafter engine properties in an application-context bean?CrafterCMS:如何在应用程序上下文 bean 中使用 Crafter 引擎属性?
【发布时间】:2018-08-13 08:12:54
【问题描述】:

我正在使用扩展 JdbcTemplate 的类连接到外部数据库。我的问题是我不能使用 Groovy API 的 globalProperties 因为 Jdbc。

我在 server-config.properties 中添加了我需要的这些属性:

studio.db.driverClassName
studio.db.url
studio.db.username
studio.db.password

我正在尝试在我的 application-context.xml 中访问它们:

<bean id="jdbc" class="com.dbJdbcTemplate">
    <constructor-arg ref="datasource"/>
</bean>

<bean id="datasource" class="org.apache.commons.dbcp.BasicDataSource">
    <property name="url" value="${studio.db.url}"/>
    <property name="driverClassName" value="${studio.db.driverClassName}"/>
    <property name="username" value="${studio.db.username}"/>
    <property name="password" value="${studio.db.password}"/>
</bean>

我收到此错误:

原因:org.springframework.jdbc.CannotGetJdbcConnectionException: 不能 获取 JDBC 连接;嵌套异常 org.apache.commons.dbcp.SQLNestedException:无法加载 JDBC 驱动程序类“${studio.db.driverClassName}”

如何正确访问我的 bean 中的属性?

【问题讨论】:

    标签: content-management-system spring-jdbc crafter-cms


    【解决方案1】:

    在您的网站application-context.xml 中添加&lt;bean class="org.springframework.context.support.PropertySourcesPlaceholderConfigurer" parent="crafter.properties"/&gt;,如此处所示https://docs.craftercms.org/en/3.0/site-administrators/engine/engine-site-configuration.html#id3。这些行让您可以访问 Engine 的全局属性。

    【讨论】:

      猜你喜欢
      • 2017-03-04
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 1970-01-01
      • 2023-03-17
      • 1970-01-01
      相关资源
      最近更新 更多