IDEA: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value

Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value

##

将Eclipse上的Spring+MyBatis项目导入到IDEA上来,出现这种错误,按理说是怎么都不会有这个错误的,因为在eclipse上是可以跑的。

Type Exception Report

Message Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for njupt.mapper.StudentMapper.selectByStuId
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for njupt.mapper.StudentMapper.selectByStuId
    org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:980)
    org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:859)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:635)
    org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:844)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:121)
    org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)

错误原因是在IDEA中不会将Sources下的XML文件发布

可以看到target文件夹中开始没有我们的StudentMapper.xml文件
这里写图片描述

解决方法

  1. 把xml直接拖到resourse,运行!但是这个方法 ,其实破坏了包结构。

  2. 尝试新的方法:不需要移动mapper.xml,推荐在pom文件中找到

<build></build>
    在其中添加以下几行,用于扫描到xml文件。
<resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.xml</include>
                </includes>
            </resource>
</resources>

解决方法来自https://blog.csdn.net/tiancaijunm/article/details/70571134

posted @ 2018-05-07 09:05  wei1  阅读(780)  评论(0编辑  收藏  举报