2
回答
ssm框架,配置多数据源,初始化后只注入了一个数据源,求大神把脉!
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

数据源--dataAccessContext.xml
<!-- 数据源定义,使用Apache DBCP 连接池 -->
<bean id="dataSource" name="default_ds"
class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.cloudmaster.driverClassName}" />
<property name="url" value="${jdbc.cloudmaster.url}" />
<property name="username" value="${jdbc.cloudmaster.username}" />
<property name="password" value="${jdbc.cloudmaster.password}" />
<property name="initialSize" value="${jdbc.cloudmaster.initialSize}" />
<property name="maxActive" value="${jdbc.cloudmaster.maxActive}" />
<property name="maxIdle" value="${jdbc.cloudmaster.maxIdle}" />
<property name="minIdle" value="${jdbc.cloudmaster.minIdle}" />
<property name="validationQuery" value="${jdbc.cloudmaster.validationQuery}" />
</bean>
<!-- monitoropenStack数据源定义,使用Apache DBCP 连接池-->
<bean id="monitoropenStackDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.openstack.driverClassName}"/>
<property name="url" value="${jdbc.openstack.url}" />
<property name="username" value="${jdbc.openstack.username}" />
<property name="password" value="${jdbc.openstack.password}" />
<property name="initialSize" value="${jdbc.openstack.initialSize}"/>
<property name="maxActive" value="${jdbc.openstack.maxActive}"/>
<property name="maxIdle" value="${jdbc.openstack.maxIdle}"/>
<property name="minIdle" value="${jdbc.openstack.minIdle}"/>
<property name="validationQuery" value="${jdbc.openstack.validationQuery}"/>
<property name="testWhileIdle" value="${jdbc.openstack.testWhileIdle}"/> 
<property name="timeBetweenEvictionRunsMillis" value="${jdbc.openstack.timeBetweenEvictionRunsMillis}"/> 
</bean>

mybatis.xml

<!-- cloudmaster数据源 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean" >
<property name="dataSource" ref="dataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-config.xml"></property>
</bean>
<bean id="mybatisDao" class="com.chinamobile.bcop.dao.impl.MybatisDAOImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory"></property>
</bean>
<!-- monitoropenStack数据源 -->
<bean id="sqlSessionFactory_monitoropenStack" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="monitoropenStackDataSource" />
<property name="configLocation" value="classpath:mybatis/mybatis-config-monitor.xml"></property>
</bean>
<bean id="monitorMybatisDao" class="com.chinamobile.bcop.dao.impl.MybatisDAOImpl">
<property name="sqlSessionFactory" ref="sqlSessionFactory_monitoropenStack"></property>
</bean>

service层注入
    @Autowired
    @Qualifier("mybatisDao")
    private IMybatisDAO mybatisDao;
    @Autowired
    @Qualifier("monitorMybatisDao")
    private IMybatisDAO monitorMybatisDao;

在请求数据库做插入的时候monitorMybatisDao这个类的数据源和mybatisDao是同一个,求大神们给指导,哪里出现了问题?

后面在service层断点进去发现,



在service层去掉第一个dao注入后,断点发现monitorMybatisDao的数据源仍然不对,大神们这是什么问题呢?

举报
二哥学Java
发帖于1年前 2回/1K+阅
顶部