org.springframework.beans.factory.BeanCreationException: не удалось выполнить внедрение зависимостей с автопроводкой; - PullRequest
0 голосов
/ 22 мая 2018

Получение приведенной ниже ошибки при запуске сервера.

org.springframework.beans.factory.BeanCreationException: Ошибка при создании bean-компонента с именем 'kuttyJavaController': сбой внедрения зависимостей с автопроводкой;вложенное исключение: org.springframework.beans.factory.BeanCreationException: не удалось автоматически связать поле: private org.springframework.jdbc.core.JdbcTemplate com.service.KuttyJavaController.jdbcoriensb2c;вложенное исключение - org.springframework.beans.factory.NoSuchBeanDefinitionException: для зависимости не найден квалифицирующий компонент типа [org.springframework.jdbc.core.JdbcTemplate]: ожидается, что по крайней мере 1 компонент, который квалифицируется как кандидат для автоматического подключения для этой зависимости.Аннотации зависимостей: {@ org.springframework.beans.factory.annotation.Autowired (обязательно = 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
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 Ответ

0 голосов
/ 22 мая 2018

Названия ваших бобов не совпадают.Например, вы определили следующее:

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

Тем не менее, вы вызываете его, используя:

//Nstore B2b
private JdbcTemplate jdbcnstoreb2b;

Это должно быть (конечно, также в случае верблюда):

//Nstore B2b
private JdbcTemplate nstoreb2btemplate;
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...