expected at least 1 bean which qualifies as autowire candidate for this dependency

 

第一种状况:
i think it comes from this line in your XML file: spring

Java代码 sql

  1. <context:component-scan base-package="com.xxx.controller" />  

Replace it by: mybatis

Java代码app

  1. <context:component-scan base-package="com.xxx" />  


第二种状况: 注入映射器 
添加以下配置到Mybatis配置文件中,这种配置比较繁琐,每一个接口都要配置下 this

Java代码 .net

  1. <bean id="accountMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">  
  2.       <property name="mapperInterface" value="com.mxy.mapper.AccountMapper" />  
  3.       <property name="sqlSessionFactory" ref="sqlSessionFactory" />  
  4. </bean>  

或者添加下面的内容。这个方法比较好component

Java代码 接口

  1. <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">  
  2.         <property name="basePackage" value="com.mxy.mapper" />  
  3. </bean>  


第三种状况:在serviceImpl中要类上要添加@Service get

Java代码 it

  1. @Service  
  2. public class XxxServiceImpl implements XxxService { } 
相关文章
相关标签/搜索