今天配置spring+myBatis的时候,使用注解@Autowired把持久层dao注入service层的时候总是报错。

spring + myBatis 常见错误:@Autowired注解失败


查了好久才发现,居然是配置文件路径写错了。basepackge的路径一定要正确

<!-- DAO接口所在包名,spring会自动查找其下的类 -->
<bean class="org.mybatis.spring.mapper.MapperScannerConfigurer">
<property name="sqlSessionFactoryBeanName" value="sqlSessionFactory" />
<!-- 如果这里路径和持久层的路径不对,接口注解就会失败 -->
<property name="basePackage" value="com.mapper" />
</bean>

 

相关文章:

  • 2021-11-14
  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2021-06-28
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2022-02-01
  • 2021-11-23
  • 2022-03-07
  • 2022-12-23
  • 2021-08-22
相关资源
相似解决方案