zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    如何成为一名专家级的开发人员
    ZapThink探讨未来十年中企业IT的若干趋势
    Adobe CTO:Android将超预期获50%份额
    我的美国之行
    用上Vista了!
    用pylint来检查python程序的潜在错误
    delegate in c++ (new version)
    The GNU Text Utilities
    python程序转为exe文件
    c++头文件,cpp文件,makefile,unit test自动生成器
  • 原文地址:https://www.cnblogs.com/wei1/p/9582083.html
Copyright © 2011-2022 走看看