130???
2020-04-29 11:49
采纳率: 66.7%
浏览 299
已采纳

Idea中的Mybaties中配置文件的mapper无法找到xml文件!

图片说明图片说明图片说明

这是错误信息


Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com.dao.UserDao.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.dao.UserDao.xml
    at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:64)
    at test.main(test.java:21)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.dao.UserDao.xml
    at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
    at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
    at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
    ... 2 more
Caused by: java.io.IOException: Could not find resource com.dao.UserDao.xml
    at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:114)
    at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:100)
    at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:371)
    at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:119)
    ... 4 more

Process finished with exit code 1

求解答

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • 编程爱好者熊浪 2020-04-29 13:40
    已采纳

    mapper的三种写法,你对下你的写法对吗?
    接口用class (接口)

    <mapper class="org.mybatis.mappers.UserMapper"/>
    

    绝对路径用url (绝对路径)

    <mapper url="file:///var/mappers/UserMapper.xml"/>
    

    xml文件用resource(相对路径)

    <mapper resource="org/mybatis/mappers/UserMapper.xml"/>
    

    图片说明

    点赞 打赏 评论
  • Json-Huang 2020-04-29 12:02

    文件名前面加上类路经classpath:试试

    点赞 打赏 评论

相关推荐 更多相似问题