zoukankan      html  css  js  c++  java
  • Mybatis 异常:Cause: java.io.IOException: Could not find resource com.xxx.xxx.xml

    转载请注明出处:

    https://www.cnblogs.com/Xi-Chen00/p/12619072.html

    最近在复习mybatis知识的时候,遇到这个异常:

    Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
    ### Error building SqlSession.
    ### The error may exist in com/spring/repository/AccountRepository.xml
    ### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/spring/repository/AccountRepository.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.spring.test.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/spring/repository/AccountRepository.xml
    	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:121)
    	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:98)
    	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:78)
    	... 2 more
    Caused by: java.io.IOException: Could not find resource com/spring/repository/AccountRepository.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
    
    

    检查运行类配置文件名,确定没错:

    检查mybatis的配置文件,注册的xml的路径确定没写错(路径用/,有.xml后缀):

    检查了.xml映射的namespace,确定也没写错(路径用. , 没有后缀):

    无论反复检查代码,也导入了mybatis依赖。最后想了一下,找不到文件是不是因为maven工程没有扫描到xml文件?(这点还是容易被忽略的,maven默认扫描resource目录)

    在pom的build中添加扫描java目录下xml文件的依赖就成功了:

        <resources>
          <resource>
            <directory>src/main/java</directory>
            <includes>
              <include>**/*.xml</include>
            </includes>
          </resource>
        </resources>
    
  • 相关阅读:
    24、可靠信号与不可靠信号
    24、sed用法
    26、linux shell常用的几个函数,diff
    21、Posix共享内存
    23、修改vim的tab,使其占4个空格
    25、linux shell常用的几个函数,sort
    Console算法有一分数序列:2/1,3/2,5/3,8/5,13/8,21/13...求出这个数列的前20项之和
    Console算法[for,if]一水仙花数(Water flower)
    Console算法回文数
    Console算法[for,if]有5个人坐在一起,问第五个人多少岁?他说比第4个人大2岁。问第4个人岁数
  • 原文地址:https://www.cnblogs.com/Xi-Chen00/p/12619072.html
Copyright © 2011-2022 走看看