web.xml配置
<!-- Processes application requests --> <servlet> <servlet-name>appServlet</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name><param-value>${profiles.hsf-context}</param-value></init-param> <load-on-startup>1</load-on-startup> </servlet>
maven打包后
mvn compile package -Pproduction
${profiles.hsf-context}将会被替换为/WEB-INF/spring/appServlet/servlet-context.xml
pom文件配置
<!-- 这个插件必须 -->
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.1.1</version> <configuration> <webResources> <resource> <directory>src/main/webapp</directory> <filtering>true</filtering> </resource> </webResources> </configuration> </plugin>
<profiles> <profile> <!-- 测试环境 --> <id>test</id> <properties> <profiles.active>test</profiles.active> <profiles.rpc-context>/WEB-INF/spring/appServlet/servlet-context.xml</profiles.rpc-context> </properties> </profile> <profile> <!-- 生产环境 --> <id>production</id> <properties> <profiles.active>production</profiles.active> <profiles.rpc-context>/WEB-INF/spring/appServlet/servlet-context.xml</profiles.rpc-context> </properties> <activation> <activeByDefault>true</activeByDefault> </activation> </profile> </profiles>