ssm 出现 Method threw 'org.apache.ibatis.binding.BindingException' exception.Invalid bound statement (not found)……

时间:2022-02-03 21:39:20

运行数据库的增删改查时出现 500状态码 并且提示 Method threw 'org.apache.ibatis.binding.BindingException' exception.Invalid bound statement (not found),

后来才知道,IDEA的打包时默认不将 xml配置文件打包进去?毕竟在ssm中,SQL语句都是在配置文件中实现的,如果没打包进去怎么运行得起来。

dao层的pom.xml 如下:

 1 <?xml version="1.0" encoding="UTF-8"?>
 2 
 3 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
 5     <parent>
 6         <artifactId>common-parent</artifactId>
 7         <groupId>com.example.edu</groupId>
 8         <version>1.0-SNAPSHOT</version>
 9     </parent>
 10     <modelVersion>4.0.0</modelVersion>
 11 
 12     <artifactId>edu-dao</artifactId>
 13     <packaging>jar</packaging>   <!--希望打包成jar包-->
 14 
 15     <name>edu-dao</name>
 16     <!-- FIXME change it to the project's website -->
 17     <url>http://www.example.com</url>
 18 
 19     <properties>
 20         <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
 21         <maven.compiler.source>1.7</maven.compiler.source>
 22         <maven.compiler.target>1.7</maven.compiler.target>
 23     </properties>
 24 
 25     <dependencies>
 26 
 27         <dependency>
 28             <groupId>junit</groupId>
 29             <artifactId>junit</artifactId>
 30             <version>4.11</version>
 31             <scope>test</scope>
 32         </dependency>
 33 
 34 
 35         <dependency>
 36             <!--依赖model-->
 37             <!--那么问题来了,dao这里依赖model的作用是什么呢?-->
 38             <artifactId>edu-model</artifactId>
 39             <groupId>com.example.edu</groupId>
 40             <version>1.0-SNAPSHOT</version>
 41         </dependency>
 42 
 43         <!--导入mybatis的jar包-->
 44 
 45         <dependency>
 46             <groupId>org.mybatis</groupId>
 47             <artifactId>mybatis</artifactId>
 48             <version>${mybatis.version}</version>
 49         </dependency>
 50 
 51 
 52         <!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
 53         <!--数据库驱动-->
 54         <dependency>
 55             <groupId>mysql</groupId>
 56             <artifactId>mysql-connector-java</artifactId>
 57             <version>${mysql.version}</version>
 58         </dependency>
 59 
 60 
 61     </dependencies>
 62 
 63     <build>
 64 
 65         <!--以下增加的内容可以在idea直接构建时就将xml文件一起打包 此时是需要依赖jstl -->
 66         <resources>
 67             <resource>
 68                 <directory>src/main/java</directory>
 69                 <includes>
 70                     <include>**/*.xml</include>
 71                 </includes>
 72             </resource>
 73         </resources>
 74 
 75         <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
 76             <plugins>
 77                 <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
 78                 <plugin>
 79                     <artifactId>maven-clean-plugin</artifactId>
 80                     <version>3.1.0</version>
 81                 </plugin>
 82                 <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
 83                 <plugin>
 84                     <artifactId>maven-resources-plugin</artifactId>
 85                     <version>3.0.2</version>
 86 
 87 
 88                     <!--解决手动mvn时没将xml文件包括入内的问题-->
 89                     <!-- <executions>  90  <execution>  91  <id>copy-xmls</id>  92  <phase>process-sources</phase>  93  <goals>  94  <goal>copy-resources</goal>  95  </goals>  96  <configuration>  97  <outputDirectory>${basedir}/target/classes</outputDirectory>  98  <resources>  99  <resource> 100  <directory>${basedir}/src/main/java</directory> 101  <includes> 102  <include>**/*.xml</include> 103  </includes> 104  </resource> 105  </resources> 106  </configuration> 107  </execution> 108  </executions>-->
109 
110                 </plugin>
111                 <plugin>
112                     <artifactId>maven-compiler-plugin</artifactId>
113                     <version>3.8.0</version>
114                 </plugin>
115                 <plugin>
116                     <artifactId>maven-surefire-plugin</artifactId>
117                     <version>2.22.1</version>
118                 </plugin>
119                 <plugin>
120                     <artifactId>maven-jar-plugin</artifactId>
121                     <version>3.0.2</version>
122                 </plugin>
123                 <plugin>
124                     <artifactId>maven-install-plugin</artifactId>
125                     <version>2.5.2</version>
126                 </plugin>
127                 <plugin>
128                     <artifactId>maven-deploy-plugin</artifactId>
129                     <version>2.8.2</version>
130                 </plugin>
131                 <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
132                 <plugin>
133                     <artifactId>maven-site-plugin</artifactId>
134                     <version>3.7.1</version>
135                 </plugin>
136                 <plugin>
137                     <artifactId>maven-project-info-reports-plugin</artifactId>
138                     <version>3.0.0</version>
139                 </plugin>
140             </plugins>
141         </pluginManagement>
142     </build>
143 </project>

 

注意看66-73行间的代码,加上这部分后每次运行时idea会自动将xml配置文件打包进来

后面的88-108间的代码也可以解决这个问题,不过它每次都要你手动mvn insatll 来打包,当xml有改变时如果不手动打包的话就用不了了。