maven spring profile 协同

  请在网上查相关的使用情景,这里直接上要点。另外,可能不只一种方法,但这里只有一种。

  1、POM.XML片段,使web.xml文件中有关活跃spring profile的内容可以被maven自动替换

            <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>

  2、POM.XML片段,在profile中自定义属性。注意id与属性值的一致

            <profile>
                <id>test</id>
                <properties>
                    <profile.active>test</profile.active>
                        ……
                </properties>
            </profile>
            <profile>
                <id>dev</id>
                <properties>
                    <profile.active>dev</profile.active>
                        ……
                </properties>
            </profile>    

  3、web.xml片段,使用maven中定义的属性

    <context-param>
        <param-name>spring.profiles.active</param-name>
        <param-value>${profile.active}</param-value>
    </context-param>

  4、spring配置文件,定义各种Beans的所适用的profile。

    <beans profile="test,online">
    </beans>
    <beans profile="dev">
    </beans>

 

posted on 2014-05-06 09:44  李学斌  阅读(917)  评论(0编辑  收藏  举报