spring5整合mybatis3.4.6配置mapperLocations错误

凶羊 2018-12-19 06:07:37
配置spring5和mybatis3.4.6时候配置一直报错,快搞疯了



<!-- 配置MyBatis SqlSessionFactory -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mapperLocations" value="classpath:mappers/*.xml" />
</bean>


上面这行红色字体的代码注释掉就可以通过了,不注释掉就报错:

Error creating bean with name 'sqlSessionFactory' defined in file [E:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\note\WEB-INF\classes\conf\spring-mybatis.xml]: Invocation of init method failed; nested exception is org.springframework.core.NestedIOException: Failed to parse mapping resource: 'file [E:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\note\WEB-INF\classes\mappers\UserMapper.xml]'; nested exception is org.apache.ibatis.builder.BuilderException: Error parsing Mapper XML. The XML location is 'file [E:\eclipse-workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\note\WEB-INF\classes\mappers\UserMapper.xml]'. Cause: org.apache.ibatis.builder.BuilderException: Error resolving class. Cause: org.apache.ibatis.type.TypeException: Could not resolve type alias 'cn.tedu.note.entity.User'. Cause: java.lang.ClassNotFoundException: Cannot find class: cn.tedu.note.entity.User
...全文
280 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
零落飞花雨 2018-12-19
  • 打赏
  • 举报
回复
你这个应该是classpath路径写错了,应该放在entity所在的包里面
咸哼酒家 2018-12-19
  • 打赏
  • 举报
回复
UserMapper.xml 解析错误,
该XML中用到了cn.tedu.note.entity.User 这个类,可是实际项目中没有这个路径的类
雾里看花の 2018-12-19
  • 打赏
  • 举报
回复
在classpath后加个*试试?

<property name="mapperLocations" value="classpath*:mappers/*.xml" />
凶羊 2018-12-19
  • 打赏
  • 举报
回复
引用 4 楼 leijie_csdn 的回复:
mappers里的User是不是有resultMap写错了 可用尝试检查一下
就是由于resultMap路径写错了导致的,谢谢大神
leijie_csdn 2018-12-19
  • 打赏
  • 举报
回复
mappers里的User是不是有resultMap写错了 可用尝试检查一下

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧