0
votes

Getting the below error during server start.

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'kuttyJavaController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.springframework.jdbc.core.JdbcTemplate com.service.KuttyJavaController.jdbcoriensb2c; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [org.springframework.jdbc.core.JdbcTemplate] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

Bean.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-4.0.xsd ">

    <bean id="oriensb2c"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="aa" />
            <property name="url" value="jdbc:mysql://localhost:3306/aa" />
            <property name="password" value="aa" />
    </bean>

    <bean id="oriensb2b"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="bb" />
            <property name="url" value="jdbc:mysql://localhost:3306/bb" />
            <property name="password" value="bb" />
    </bean>

    <bean id="nstoreb2c"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="cc" />
            <property name="url" value="jdbc:mysql://localhost:3306/cc" />
            <property name="password" value="cc" />
    </bean>

    <bean id="nstoreb2b"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="dd" />
            <property name="url" value="jdbc:mysql://localhost:3306/dd" />
            <property name="password" value="dd" />
    </bean>



    <!-- Definition for JDBCTemplate bean -->
    <bean id="jdbcoriensb2c" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="oriensb2c"></property>
    </bean>
    <bean id="jdbcoriensb2b" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="oriensb2b"></property>
    </bean>

    <bean id="jdbcnstoreb2c" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="nstoreb2c"></property>
    </bean>
    <bean id="jdbcnstoreb2b" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="nstoreb2b"></property>
    </bean>

    <bean id="kuttyJavaController" class="com.service.KuttyJavaController">
    <property name="jdbcoriensb2c" ref="jdbcoriensb2c"></property>
    <property name="jdbcoriensb2b" ref="jdbcoriensb2b"></property>
    <property name="jdbcnstoreb2c" ref="jdbcnstoreb2c"></property>
    <property name="jdbcnstoreb2b" ref="jdbcnstoreb2b"></property>
    </bean>
</beans>

Controller:

@Controller
public class KuttyJavaController {


    //Oriens B2c
    private JdbcTemplate jdbcoriensb2c;

    //Oriens B2b
    private JdbcTemplate jdbcoriensb2b;

    //Nstore B2c
    private JdbcTemplate jdbcnstoreb2c;

    //Nstore B2b
    private JdbcTemplate jdbcnstoreb2b;



    public void setJdbcoriensb2c(JdbcTemplate jdbcoriensb2c) {
        this.jdbcoriensb2c = jdbcoriensb2c;
    }

    public void setJdbcoriensb2b(JdbcTemplate jdbcoriensb2b) {
        this.jdbcoriensb2b = jdbcoriensb2b;
    }

    public void setJdbcnstoreb2c(JdbcTemplate jdbcnstoreb2c) {
        this.jdbcnstoreb2c = jdbcnstoreb2c;
    }

    public void setJdbcnstoreb2b(JdbcTemplate jdbcnstoreb2b) {
        this.jdbcnstoreb2b = jdbcnstoreb2b;
    }
1
Your names and refs and field names do not appear to match up. You should make them consistent.Compass
@Compass can you give an example.Explain Down Vote

1 Answers

1
votes

The names of your beans do not match up. For example, you have the following defined:

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

Yet, you are calling it using:

//Nstore B2b
private JdbcTemplate jdbcnstoreb2b;

This should be (of course also in camel case):

//Nstore B2b
private JdbcTemplate nstoreb2btemplate;