请在网上查相关的使用情景,这里直接上要点。另外,可能不仅一种方法,但这里只有一种。web
一、POM.XML片断,使web.xml文件中有关活跃spring profile的内容能够被maven自动替换spring
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>2.4</version> <configuration> <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>
二、POM.XML片断,在profile中自定义属性。注意id与属性值的一致!apache
<profile> <id>test</id> <properties> <profile.active>test</profile.active> …… </properties> </profile> <profile> <id>dev</id> <properties> <profile.active>dev</profile.active> …… </properties> </profile>
三、web.xml片断,使用maven中定义的属性app
<context-param> <param-name>spring.profiles.active</param-name> <param-value>${profile.active}</param-value> </context-param>
四、spring配置文件,定义各类Beans的所适用的profile。webapp
<beans profile="test,online"> </beans> <beans profile="dev"> </beans>