0

私は非常に奇妙な問題に直面しています。PropertyPlaceholderConfigurer クラスを介して、春の applicationcontext.xml ファイルで宣言されたデータソースのプロパティを構成しようとしています。アプリケーション コンテキスト ファイルは次のようになります。

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:ws="http://jax-ws.dev.java.net/spring/core" xmlns:wss="http://jax-ws.dev.java.net/spring/servlet"
xmlns:jms="http://www.springframework.org/schema/jms"
xsi:schemaLocation="http://jax-ws.dev.java.net/spring/servlet http://jax-ws.dev.java.net/spring/servlet.xsd
    http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd
    http://jax-ws.dev.java.net/spring/core http://jax-ws.dev.java.net/spring/core.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
    http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.4.xsd
    http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd
    http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">

<!--  Spring configurations used by LCM Impl classes -->
<bean id="lcmPropertyConfigurer"
       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:/activemq.properties</value>
            <value>classpath:/jdbc.properties</value>
        </list>
    </property>
</bean>


<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy- method="close">
<property name="driverClassName" value="${db.driverClassName}" />
<property name="url" value="${db.url}"/>
<property name="username" value="${db.username}"/>
<property name="password" value="${db.password}"/>
</bean>

<bean id="jdbcTemplate" class="org.springframework.jdbc.core.JdbcTemplate">
    <property name="dataSource" ref="dataSource"/>
</bean>
</beans>

context:property-placeholder タグも使用してみましたが、効果がないようです。上記のプロパティ ファイルは、WEB-INF/classes ディレクトリにも正常にデプロイされます。

何らかの理由で、Spring コンテナーはプロパティ ファイルをロードできますが (無効なプロパティ ファイルでチェックされ、FNF 例外がスローされます)、プロパティ プレースホルダーをその値に置き換えることはできません。

私は自分のランタイムを指している CATALINA.BASE で tomcat 7 WS を使用しています。誰もこの問題に直面したことがありますか? 解決策はありますか?

4

2 に答える 2

1

値から先頭のスラッシュを削除します。

        <value>classpath:activemq.properties</value>
        <value>classpath:jdbc.properties</value>
于 2012-02-27T10:59:22.690 に答える
0

次の構成を試してください。

<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:activemq.properties</value>
            <value>classpath:jdbc.properties</value>
        </list>
    </property>
</bean>

問題は、PropertyPlaceholderConfigurer Bean に名前を付けたことにある可能性があります。フレームワークは特定の Bean 名を検索するように構成されており、多くの場合、デフォルトの Bean 名はオブジェクト タイプに基づいて自動生成された名前であるため、ほとんどの Spring 内部 Bean には ID が与えられていません。

于 2012-10-12T05:05:19.857 に答える