最近在为项目组开发项目时,pom 文件里的打包插件maven-war-plugin 打包后,放在Tomcat下运行后,页面执行一个查询类的操作后,后台报错,如下图:
07-Nov-2017 09:40:35.848 SEVERE [http-nio-8080-exec-3] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [appServlet] in context with path [/vq] threw exception [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 com.vip.platform.vms.qa.dao.Cluster.getClusterByClusterTypeAndEnv
### Cause: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.vip.platform.vms.qa.dao.Cluster.getClusterByClusterTypeAndEnv] with root cause
java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.vip.platform.vms.qa.dao.Cluster.getClusterByClusterTypeAndEnv
at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:832)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:665)
at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:658)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:119)
at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:113)
查了下,放在war里的文件,缺少mybatis的映射文件。
网上找了下,发现时打包时,/src/main/java 默认只会编译java源文件。问题找到了。接下来是怎么解决。
网上大家基本是放在 src/java/resource 目录下,直接解决问题。我不想这么做,因为需要改动spring 配置文件。
查了下官网的文档,可以pom文件里,加上这些配置
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<webResources>
<resource>
<!-- this is relative to the pom.xml directory -->
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<targetPath>WEB-INF/classes</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
问题解决了