第一種狀況:
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 { }