maven项目web配置文件多环境配置

web.xml配置


<servlet>
   <servlet-name>appServletservlet-name>
   <servlet-class>org.springframework.web.servlet.DispatcherServletservlet-class>
   <init-param>
      <param-name>contextConfigLocationparam-name>
      <param-value>${profiles.hsf-context}param-value>
   init-param>
   <load-on-startup>1load-on-startup>
servlet>

maven打包后

 mvn compile  package -Pproduction

${profiles.hsf-context}将会被替换为/WEB-INF/spring/appServlet/servlet-context.xml

pom文件配置

<plugin>
   <groupId>org.apache.maven.pluginsgroupId>
   <artifactId>maven-war-pluginartifactId>
   <version>2.1.1version>
   <configuration>
      <webResources>
         <resource>
            <directory>src/main/webappdirectory>
            <filtering>truefiltering>
         resource>
      webResources>
   configuration>
plugin>

<profiles>
   <profile>
      
      <id>testid>
      <properties>
         <profiles.active>testprofiles.active>
         <profiles.rpc-context>/WEB-INF/spring/appServlet/servlet-context.xmlprofiles.rpc-context>
      properties>
   profile>
   <profile>
      
      <id>productionid>
      <properties>
         <profiles.active>productionprofiles.active>
         <profiles.rpc-context>/WEB-INF/spring/appServlet/servlet-context.xmlprofiles.rpc-context>
      properties>
      <activation>
         <activeByDefault>trueactiveByDefault>
      activation>

   profile>
profiles>

你可能感兴趣的:(编程)