Spring配置文件引用:
<bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>${env.dir}jdbc.properties</value>
</list>
</property>
</bean>
web.xml配置文件引用:
<context-param>
<param-name>spring.profiles.active</param-name>
<param-value>${profiles.active}</param-value>
</context-param>
<filter>
<filter-name>CASFilter</filter-name>
<filter-class>org.jasig.cas.client.authentication.AuthenticationFilter</filter-class>
<init-param>
<param-name>casServerLoginUrl</param-name>
<!-- 下面的URL是Cas服务器的登录地址 -->
<param-value>https://cas.oa.vipshop.com:8443/login</param-value>
</init-param>
<init-param>
<param-name>serverName</param-name>
<!-- 下面的URL是具体某一个应用的访问地址 -->
<param-value>${cas.url}</param-value>
</init-param>
</filter>
<build>
<finalName>****</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<warName>****</warName>
<webResources>
<resource>
<filtering>true</filtering>
<directory>src/main/webapp</directory>
<includes>
<include>**/web.xml</include>
</includes>
</resource>
</webResources>
<warSourceDirectory>src/main/webapp</warSourceDirectory>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<profiles>
<!-- 开发环境,默认激活 。 执行指令 mvn clean install/package -->
<profile>
<id>development</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<properties>
<env.dir>classpath:</env.dir>
<cas.url>http://localhost</cas.url>
<profiles.active>development</profiles.active>
</properties>
</profile>
<!-- 测试环境 ,执行指令 mvn clean install/package -P test -->
<profile>
<id>test</id>
<properties>
<env.dir>file:/apps/</env.dir>
<cas.url>http://localhost</cas.url>
<profiles.active>test</profiles.active>
</properties>
</profile>
<!-- 生产环境 ,执行指令 mvn clean install/package -P production -->
<profile>
<id>production</id>
<properties>
<env.dir>file:/apps/</env.dir>
<cas.url>http://ip:port</cas.url>
<profiles.active>production</profiles.active>
</properties>
</profile>
</profiles>
pom配置中
<resources>
<resource>
<directory>src/main/resources/</directory>
<filtering>true</filtering>
</resource>
<resource>
<directory>src/main/webapp/WEB-INF/</directory>
<filtering>true</filtering>
</resource>
</resources>
这段为需要扫描替换的路径
<profiles>中的配置为每一种install -P profile 的变量需要替换的值