第一种状况:
i think it comes from this line in your XML file: spring
Java代码 sql
- <context:component-scan base-package="com.xxx.controller" />
Replace it by: mybatis
Java代码app
- <context:component-scan base-package="com.xxx" />
第二种状况: 注入映射器
添加以下配置到Mybatis配置文件中,这种配置比较繁琐,每一个接口都要配置下 this
Java代码 .net
- <bean id="accountMapper" class="org.mybatis.spring.mapper.MapperFactoryBean">
- <property name="mapperInterface" value="com.mxy.mapper.AccountMapper" />
- <property name="sqlSessionFactory" ref="sqlSessionFactory" />
- </bean>
或者添加下面的内容。这个方法比较好component
Java代码 接口
- <bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
- <property name="basePackage" value="com.mxy.mapper" />
- </bean>
第三种状况:在serviceImpl中要类上要添加@Service get
Java代码 it
- @Service
- public class XxxServiceImpl implements XxxService { }