benskiiii
benskiiii

Reputation: 469

Referenced bean 'name' not found

For some strange reason, this dataSource bean is found in 3 of my dao-beans, but not in the other ones (For example Spring-name1). Whats the difference?

Referenced bean 'dataSource' not found

This is the code:

Not working bean(Spring-name1):

<?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"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="cheopsDAO" class="se.kth.domain.dao.impl.JdbcCheopsDAO">
        <property name="dataSource" ref="dataSource" />
    </bean>

</beans>

Working bean(Spring-name2):

<?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"
        xsi:schemaLocation="
        http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <bean id="thresholdDAO" class="se.kth.domain.dao.impl.JdbcThresholdDAO">
        <property name="dataSource" ref="dataSource" />
    </bean>

</beans>

Sping-Module.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"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

    <import resource="database/Spring-Datasource.xml" />
    <import resource="dao-beans/**" />
</beans>

Spring-Datasource.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans">
    <bean class="org.springframework.jdbc.datasource.DriverManagerDataSource"
        id="dataSource">
        <property value="com.mysql.jdbc.Driver" name="driverClassName" />
        <property value="jdbc:mysql://localhost:3306/test" name="url" />
        <property value="root" name="username" />
        <property value="test" name="password" />
    </bean>
</beans>

I have the required DAO files in respective package corretly, why is the second one working but not the first one? There is no difference..

Thanks in forehand!

Upvotes: 1

Views: 3155

Answers (1)

benskiiii
benskiiii

Reputation: 469

I fixed this by adding Config Sets (Bean support) for my project. Don't know if this is the exact right solution, but it removed the errors at least:

Right click on project->properties->Spring->Bean Support-> Config Sets (Do a Scan before in the previous page), then I just added them all together in a random config set. =)

Upvotes: 2

Related Questions