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>
这两者功能是一样的。根据需要去掉其中之一即可
相关文章推荐
- Noqualifying bean of type [org.apache.solr.client.solrj.SolrServer] is defined:expected single match
- No qualifying bean of type [org.apache.solr.client.solrj.SolrServer] found for dependency: expected
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.oskyhang.gbd.service.UserService] found for dependency: expected at least 1 bean which qualifies as aut
- 项目启动时No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined但正常运行
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'org.act
- No qualifying bean of type is defined: expected single matching bean but found 2
- No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- No qualifying bean of type [org.springframework.jms.core.JmsTemplate] is defined
- Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined(转)
- Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.lin
- No qualifying bean of type 'org.apache.catalina.User' available
- No unique bean of type [xxxxx] is defined: expected single bean but...
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- No qualifying bean of type 'org.apache.velocity.app.VelocityEngine
- shiro错误 org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type
- spring boot+mybatis 多数据源报错 No qualifying bean of type [javax.sql.DataSource] is defined:
- Spring 定时器 No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
- spring boot+mybatis 多数据源报错 No qualifying bean of type [javax.sql.DataSource] is defined:
- org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.wan