您的位置:首页 > 运维架构 > Apache

No qualifying bean of type [org.apache.ibatis.session.SqlSessionFactory] is defined: expected single

2019-03-22 11:09 1371 查看
[code]<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:mybatis="http://mybatis.org/schema/mybatis-spring"
xmlns="http://www.springframework.org/schema/beans"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring.xsd">
<mybatis:scan base-package="xxx.xxx.xxx"/>
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.user}"/>
<property name="password" value="${jdbc.pwd}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="filters" value="stat,config"/>
<property name="connectionProperties" value="${jdbc.password.encrypt}"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnReturn" value="false"/>
</bean>

<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation" value="classpath:spring-mybatis.xml"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage"
value="xxx.xxx.xxx"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"/>
</bean>

<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>

<bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"
scope="prototype">
<property name="transactionManager" ref="transactionManager"/>
<property name="isolationLevelName" value="ISOLATION_DEFAULT"/>
</bean>

<tx:annotation-driven transaction-manager="transactionManager"/>

<bean id="dataSource_r" class="com.alibaba.druid.pool.DruidDataSource"
init-method="init" destroy-method="close">
<property name="url" value="${jdbc.url.r}"/>
<property name="username" value="${jdbc.user.r}"/>
<property name="password" value="${jdbc.pwd.r}"/>
<property name="initialSize" value="${jdbc.initialSize}"/>
<property name="maxActive" value="${jdbc.maxActive}"/>
<property name="filters" value="stat,config"/>
<property name="connectionProperties" value="${jdbc.password.encrypt}"/>
<property name="testOnBorrow" value="false"/>
<property name="testWhileIdle" value="true"/>
<property name="testOnReturn" value="false"/>
</bean>

<bean id="sqlSessionFactory_r" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource_r"/>
<property name="configLocation" value="classpath:spring-mybatis.xml"/>
</bean>

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="xxx.xxx.xxx"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_r"/>
</bean>
</beans>
[/code]

 

出现No qualifying bean of type [org.apache.ibatis.session.SqlSessionFactory] is defined: expected single主要原因是配置中同时出现<mybatis:scan base-package="xxx.xxx.xxx"/>和

<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="basePackage" value="xxx.xxx.xxx"/>
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory_r"/>
</bean>

这两者功能是一样的。根据需要去掉其中之一即可

 

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐