【错误处理】Mybatis绑定错误 Invalid bound statement (not found)

        隔了好久重新搭建SSM框架,出现了好多BUG,但排查,解决BUG的同时也让我更加深入地了解到Tomcat SSM框架等技术的运行原理。

        【错误原因简述】

                相信大家出现这个问题的时候都会很惊讶,自己的Dao层,Mapper都是自动生成的,怎么可能错呢?

            是的,Mybatis自动生成的代码确实没出问题,往往是因为Tomcat在将工程打包的时候出错了。

            往往是因为Tomcat在将工程打成war包运行时,漏了.xml文件,或.properties文件。

        【解决方法】

                在pom.xml文件的<build>标签内加入这段代码:

                强制扫描properties,xml文件

        <resources>  
            <resource>  
                <directory>src/main/java</directory>  
                <includes>  
                    <include>**/*.properties</include>  
                    <include>**/*.xml</include>  
                </includes>  
                <filtering>false</filtering>  
            </resource>  
            <resource>  
                <directory>src/main/resources</directory>  
                <includes>  
                    <include>**/*.properties</include>  
                    <include>**/*.xml</include>  
                </includes>  
                <filtering>false</filtering>  
            </resource>  
        </resources>


            BUG的解决除了自己的探索还受到了其他优秀博客的启发。

            如果没能帮你解决问题,可以参考这个博客,写得很详细!希望能给你带来帮助

扫描二维码关注公众号,回复: 2395575 查看本文章

            https://www.jianshu.com/p/800fe918cc7a

                

猜你喜欢

转载自blog.csdn.net/jiweilai1/article/details/80472448