Mybatis报错
Error creating bean with name ‘sqlSessionFactory’ defined in class path resource [org/mybatis/spring/boot/autoconfigure/MybatisAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.apache.ibatis.session.SqlSessionFactory]: Factory method ‘sqlSessionFactory’ threw exception; nested exception is java.io.FileNotFoundException: class path resource [Mapper/*.xml] cannot be opened because it does not exist
这是第一时间检查mapper是否被扫描到了,因为报sqlbean未能创建一般都是这几个原因:
- Mapper没能被扫描,路径不正确
- xml配置文件中的包名路径不正确,未能正确对应实体类
- yml中的mapper位置不对
一定要仔细!!
mybatis:
config-location: classpath:Mapper/*.xml
这个不是xml文件的路径配置,下面才是正确的
mybatis:
mapper-locations: classpath:Mapper/*.xml
注意是mapper-locations不是config-location