maven项目在本地运行的时候没有问题,一旦把war包部署到测试机上就不能运行。查看了一下tomcat日志发现抛出这样的错误:invalid bound statement (not found),后面是找不到某个Mapper类等等。
经提醒解压war包,发现WEB_INF/classes/dao/mapper下面根本没有包含相应的xml文件。修改pom.xml,在<build>结点里加入以下语句
<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>
总之就是把要打包的文件类型都加进来。**/*.的写法是为了确保子文件夹下的内容也能打包。再部署之后就可以正常运行了。