maven项目在ide中编译出的war包一般不会有很多问题。
但是经过集成环境打war包会出现war包中打不进xml、properties等文件。这样打war包不会报错,但是war包放进tomcat中部署就报错了。
解决方法
在pom.xml的build节点配置src/main/java和src/main/resources
<build>
<resources>
<!-- 编译之后包含xml -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
<!-- 编译之后包含xml和properties -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
项目目录
1.打包后war包目录
将war包放入E:\tomcat7\webapps目录下,启动tomcat
报错
没找到me/gacl/mapping这个文件夹
原因
集成环境打包没有将src/main/java目录下的.xml文件打包进去
解决方法
在pom.xml的build节点配置src/main/java
<build>
<resources>
<!-- 编译之后包含xml -->
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
2.打包后war包目录
将war包放入E:\tomcat7\webapps目录下,启动tomcat
启动正常
访问地址
http://localhost:8080/spring_mvc/hello/mvc
错误信息
root cause
org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Failed to import bean definitions from URL location [classpath:spring/spring-mvc.xml]
Offending resource: ServletContext resource [/WEB-INF/spring-context.xml]; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring/spring-mvc.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring/spring-mvc.xml] cannot be opened because it does not exist
错误分析
spring/spring-mvc.xml文件不存在,
原因
集成环境打包没有将src/main/java目录下的.xml文件和.properties文件打包进去
解决方法
在pom.xml的build节点配置src/main/java
<build>
<resources>
<!-- 编译之后包含xml和properties -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>