IDE:IntelliJ
框架:SpringBoot+Mybatis
在使用@autowired注入时,如果是在xml中使用配置生成代理对象
<mybatis:scan base-package="com.kingdon.dao"/>
然后在相应的dao上使用@Mapper注解
@Mapper
public interface XxxDao {...}
此时IDE会报警
@Autowired
XxxDao xxxDao;//Could not autowire. No beans of 'XxxDao' type found.
实际上启动服务是可以正常运行的,但是为了去掉报错信息,我又在xml中配置了bean
<bean id="xxxDao" class="org.mybatis.spring.mapper.MapperFactoryBean">
<property name="mapperInterface" value="me.kingdon.dao.XxxDao"/>
<property name="sqlSessionFactory" ref="xxxsqlSessionFactory"/>
</bean>
此时虽然不报错,但是实际上注册了2个bean,具体有多少影响我没有去探究,但是有一条很重要的影响,就是会影响@Transational声明式事务
用xml配置的bean的操作会自动提交,无法参与@Transational配置的事务