idea+mybatis The error may exist in com/XXXX/dao/UserDaoMapper.xml

 报错信息如下

Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException: 
### Error building SqlSession.
### The error may exist in com/XXXX/dao/UserDaoMapper.xml
### Cause: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/bdqn/dao/UserDaoMapper.xml
	at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:23)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:79)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:63)
	at com.bdqn.TestStudent.main(TestStudent.java:37)
Caused by: org.apache.ibatis.builder.BuilderException: Error parsing SQL Mapper Configuration. Cause: java.io.IOException: Could not find resource com/bdqn/dao/UserDaoMapper.xml
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:106)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parse(XMLConfigBuilder.java:89)
	at org.apache.ibatis.session.SqlSessionFactoryBuilder.build(SqlSessionFactoryBuilder.java:77)
	... 2 more
Caused by: java.io.IOException: Could not find resource com/bdqn/dao/UserDaoMapper.xml
	at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:108)
	at org.apache.ibatis.io.Resources.getResourceAsStream(Resources.java:95)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.mapperElement(XMLConfigBuilder.java:315)
	at org.apache.ibatis.builder.xml.XMLConfigBuilder.parseConfiguration(XMLConfigBuilder.java:104)
	... 4 more

原因

    找不到mapper文件因为idea默认会在resource中寻找配置文件

解决办法一:

在pom中的标签中加如下信息

 
      
        src/main/java
        
          **/*.xml
        
      
    

解决办法二:

在resource文件中写mapper文件,路径和箭头所指一致

idea+mybatis The error may exist in com/XXXX/dao/UserDaoMapper.xml_第1张图片

项目结构:

idea+mybatis The error may exist in com/XXXX/dao/UserDaoMapper.xml_第2张图片

上图中UserDaoMapper用第一种解决办法

StudentMapper用第二种解决办法实现

转载于:https://my.oschina.net/u/3535099/blog/3064120

你可能感兴趣的:(idea+mybatis The error may exist in com/XXXX/dao/UserDaoMapper.xml)