Quantcast
Channel: Spring Community Forums - Data
Viewing all articles
Browse latest Browse all 297

No unique bean of type [javax.sql.DataSource] is defined

$
0
0
Hi all.
I've done an app using spring and it works ok on Eclipse. With no errors on server startup.
My problem is when y deploy on Tomcat 6 in my test environment.
I have 4 data sources defined in context-servlet.xml

Code:

        <bean autowire="byName" id="sqlServerDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${driverSQLServer}"/>
        <property name="url" value="${urlSQLServer}${dbSQLServer}"/>
        <property name="username" value="${usernameSQLServer}"/>
        <property name="password" value="${passwordSQLServer}"/>
    </bean>
   
        <bean autowire="byName" id="mySQLDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${driverMySQL}"/>
        <property name="url" value="${urlMySQL}${dbMySQL}"/>
        <property name="username" value="${usernameMySQL}"/>
        <property name="password" value="${passwordMySQL}"/>
    </bean>
   
        <bean autowire="byName" id="RDDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${driverORACLE}"/>
        <property name="url" value="${urlRD}${dbRD}"/>
        <property name="username" value="${usernameRD}"/>
        <property name="password" value="${passwordRD}"/>
    </bean>
   
        <bean autowire="byName" id="CRMDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${driverMySQL}"/>
        <property name="url" value="${urlCRM}${dbCRM}"/>
        <property name="username" value="${usernameCRM}"/>
        <property name="password" value="${passwordCRM}"/>
    </bean>

When the test Tomcat Server start, the log shows me this error:
Code:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'usuarioDAO' defined in URL [jar:file:/home/apps/lib/internal/J.AYG.ADMIN.jar!/com/ayg/apl/admin/classes/db/UsuarioDAO.class]: Unsatisfied dependency expressed through bean property 'dataSource': : No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 4: [sqlServerDataSource, mySQLDataSource, RDDataSource, CRMDataSource]; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No unique bean of type [javax.sql.DataSource] is defined: expected single matching bean but found 4: [sqlServerDataSource, mySQLDataSource, RDDataSource, CRMDataSource]
The usuarioDAO class is for obtaing the system users to get the rights and the code related to the datasources is the following:
Code:

@Repository("usuarioDAO")
public class UsuarioDAO
{
        private JdbcTemplate jdbcTemplate;

        @Autowired
        public void setDataSource(@Qualifier("mySQLDataSource")DataSource mySQLDataSource)
        {
                this.jdbcTemplate = new JdbcTemplate(mySQLDataSource);
        }
.
.
.

}

I don't know why it works on Eclipse but it doesn't in Test environment.

I've tried many things like delete the autowire="byName" in the datasource bean definitions or change it to ByType but notjong happens. I'm very frustrated with this problem because I've searched in the forum and everybody resolved a problem like this but nothing works for me.
Please help me if you know the solution.

If more information needed, ask for it.
Thanks in advance.

Viewing all articles
Browse latest Browse all 297

Trending Articles