Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource

报错内容

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/casey/mapper/UserMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/casey/mapper/UserMapper.xml
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:82)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:66)
	at com.casey.UserMapper.main(UserMapper.java:18)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/casey/mapper/UserMapper.xml
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:122)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:99)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:80)
	... 2 more
Caused by: java.io.IOException: Could not find resource com/casey/mapper/UserMapper.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:378)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:120)
	... 4 more

报错说找不到我 xml 文件,上网查询后,发现是 idea 的 bug,src 的 xml 要通过编译必须在 pom.xml 的 build 结点加上这一段

 <build>
 	
	  <resources>
	      <resource>
	          <directory>src/main/javadirectory>
	          <includes>
	              <include>*/**/*.xmlinclude>
	          includes>
	          <filtering>truefiltering>
	      resource>
	  resources>
build>

再次编译还是一样的报错,但是 target 的 xml 已经有了,只是目录的层次错误了
Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource_第1张图片
此时我看见了这篇 blog
mybatis- Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource
我寻思咱们应该是同一个问题,于是我也重建了目录,不行;重建模块,不行。


后来才发现,加的 build 结点那一段,我自己路径没配好。。好蠢噢

<resource>
	
	<directory>src/main/javadirectory>
	<includes>
	    
	    
	    <include>*/*/**/*.xmlinclude>
	includes>
	
	<filtering>falsefiltering>
resource>

这样就可以了~

你可能感兴趣的:(java,intellij-idea,mybatis,maven,xml)