Как использовать несколько источников данных в одном классе? - PullRequest
0 голосов
/ 22 мая 2018

Как сделать все источники данных, настроенные в bean.xml, доступными в моем контроллере Class1.

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="xxxbc"
        class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
            <property name="username" value="xxxbc" />
            <property name="url" value="jdbc:mysql://localhost:3306/xxxbc" />
            <property name="password" value="xxxbc" />
    </bean>

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

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

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




    <bean id="xxxcctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="xxxcc"></property>
    </bean>
    <bean id="xxxbbtemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="xxxbb"></property>
    </bean>

    <bean id="yyybctemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="yyybc"></property>
    </bean>
    <bean id="yyybbtemplate" class="org.springframework.jdbc.core.JdbcTemplate">
        <property name="dataSource" ref="yyybb"></property>
    </bean>




    <bean id="class1" class="com.controller.Class1">
        <property name="jdbcTemplate" ref="xxxcctemplate"></property>
    </bean>

    <bean id="class2" class="com.controller.Class1">
        <property name="jdbcTemplate" ref="xxxbbtemplate"></property>
    </bean>

    <bean id="class3" class="com.controller.Class1">
        <property name="jdbcTemplate" ref="yyybctemplate"></property>
    </bean>

    <bean id="class4" class="com.controller.Class1">
        <property name="jdbcTemplate" ref="yyybbtemplate"></property>
    </bean>

</beans>
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...