Spring dataSource bean definition failing

倾然丶 夕夏残阳落幕 提交于 2019-12-05 12:49:56

You probably have multiple <context:property-placeholder ... > in your project which each create a new instance of the underlying object, and is a doorway to pains...

I prefer using the following declaration for loading property files:

<bean id="propertyConfigurer"     class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <property name="locations">
        <list>
            <value>classpath:db-config.properties</value>
        </list>
    </property>
    <property name="ignoreUnresolvablePlaceholders" value="true" />
</bean>

Drop the leading slash from your location (i.e. location="WEB-INF/db.properties" ) or better yet change it to classpath:

location="classpath:db.properties"
creativeby

use org.springframework.jdbc.datasource.DriverManagerDataSource instead of org.apache.commons.dbcp.BasicDataSource

Use ignore-unresolvable="true" in you application context. Default value is 'fales' you need to set it 'true' so pass on the key to any others in the context that have not yet visited.

<context:property-placeholder ignore-unresolvable="true" location="/WEB-INF/application.properties" />
<context:property-placeholder ignore-unresolvable="true" location="/WEB-INF/dbcp.properties"/>

Make sure you have the maven dependency properly, Sping-core and Spring-context dependencies should be present in your project.

        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version></version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version></version>
        </dependency>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!