xzh393522867
互联网高级点赞收藏工程师
采纳率0%
2020-05-07 21:26

Error building SqlSession。跟着黑马学mybatis跟着敲的代码,百度了很久也不知道哪里错了,求解答。

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:

Error building SqlSession.

The error may exist in com.itheima.dao.IUserDao.xml

Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.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 com.itheima.test.MybatisTest.main(MybatisTest.java:27)

Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com.itheima.dao.IUserDao.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.itheima.dao.IUserDao.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


IUserDao.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<!--查询配置所有 -->

select *from user ;


SqlMapConfig.xml如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">


<!--配置环境-->

<!--配置mysql的环境 -->

<!--配置的事务类型 -->

<!--配置数据源(连接池)-->

<!--配置连接数据库的4个基本信息 -->






<!--指定映射配置文件的位置,映射配置文件指的是每个dao独立的配置文件 -->
<mappers>
    <mapper resource="com.itheima.dao.IUserDao.xml"></mapper>
</mappers>

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

3条回答

  • weixin_47182777 平野~ 2月前

    楼主解决了吗?

    点赞 评论 复制链接分享
  • weixin_45341366 _知道者丶 1年前

    IUserDao.xml,按ctrl点击看看嫩不能跳转到指定的xml

    点赞 评论 复制链接分享
  • hjs218 Json-Huang 1年前
    <mapper resource="com.itheima.dao.IUserDao.xml"></mapper>这里的resource应该是文件路经不是包,改成
    
    <mapper resource="com/itheima/dao/IUserDao.xml"></mapper>试试
    
    点赞 2 评论 复制链接分享

为你推荐