Spring 无法解析占位符';database.dags.driverClassName';

Spring 无法解析占位符';database.dags.driverClassName';,spring,postgresql,Spring,Postgresql,我正在尝试使用Spring创建一个访问postgres数据库的应用程序。当我运行应用程序时,会出现以下错误 org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dagsDataSource' defined in file [F:\Spring_Batch_Project\workspace\.metadata\.plugins\org.eclipse

我正在尝试使用Spring创建一个访问postgres数据库的应用程序。当我运行应用程序时,会出现以下错误

org.springframework.beans.factory.BeanDefinitionStoreException: Invalid bean definition with name 'dagsDataSource' defined in file [F:\Spring_Batch_Project\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\SpringBatchAdmin\WEB-INF\classes\META-INF\spring\batch\override\dataSource-context.xml]: Could not resolve placeholder 'database.dags.driverClassName'
这是我的datasource.context.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <bean
        class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location">
            <value>com/dirbi/oracle/resources/dbconfig/database.properties</value>
        </property>

    </bean>



    <!-- DAGs DataSource configuration -->
    <bean id="dagsDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driver" value="${database.dags.driverClassName}" />
        <property name="url" value="${database.dags.url}" />
        <property name="username" value="${database.dags.username}" />
        <property name="password" value="${database.dags.password}" />
    </bean>

    <!-- Spring Batch DataSource configuration -->
    <bean id="springBatchDataSource"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driver" value="${database.springbatch.driverClassName}" />
        <property name="url" value="${database.springbatch.url}" />
        <property name="username" value="${database.springbatch.username}" />
        <property name="password" value="${database.springbatch.password}" />
    </bean>

</beans>

非常感谢。

首先,由于不建议使用Spring 3.1
PropertyPlaceHolderConfigure
,请改用
PropertySourcesPlaceholderConfigurer
,或者只使用

其次:
com/dirbi/oracle/resources/dbconfig/database.properties
还不够。 您必须指定
资源类型前缀
。通常
类路径:
,但它取决于文件的位置。如果它只是在某个目录中,您应该使用
文件://
。 但是,它看起来像是您的
数据库.properties
在某个包中,所以使用
类路径:


顺便说一句,如果你使用PostgreSQL,为什么要使用
/oracle/

Bilanz:首先非常感谢你的回答。我在哪里写作?如果您使用PostgreSQL,为什么使用/oracle/?这个包名是我的朋友给出的,我不知道具体使用哪个数据库。
而不是
propertyplaceholderconfigure
bean定义。您的主要问题是
类路径:
位置的前缀值
database.dags.driverClassName=org.postgresql.Driver
database.dags.url=jdbc:postgresql://localhost:5433/testing
database.dags.username=postgres
database.dags.password=admin

database.springbatch.driverClassName=org.postgresql.Driver
database.springbatch.url=jdbc:postgresql://localhost:5433/springbatchadmindb
database.springbatch.username=postgres
database.springbatch.password=admin