Mybatis-Maven项目转入IDEA
1.错误描述
Exception in thread "main" org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
at demo.Demo1.main(Demo1.java:45)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:875)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:708)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:701)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
... 3 more
### Error querying database. Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:136)
at demo.Demo1.main(Demo1.java:45)
Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for dao.UserMapper.findAll
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:875)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:708)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:701)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:147)
... 3 more
2.错误原因
把mybatis-maven项目从Eclipse转入IDEA时,无法启动,报出以上错误,是因为无法找到对应的mapper-xml文件,因此需要在pom.xml中引入。
3.解决问题
需要在pom.xml文件中获取对文件的引用位置。注意文件位置!!!
<build> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.xml</include> </includes> </resource> </resources> </build>