maven spring profile 协同


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

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

            <plugin>
                <groupId>org.apache.maven.pluginsgroupId>
                <artifactId>maven-war-pluginartifactId>
                <version>2.4version>
                <configuration>
                    <webResources>
                        <resource>
                            <filtering>truefiltering>
                            <directory>src/main/webappdirectory>
                            <includes>
                                <include>**/web.xmlinclude>
                            includes>
                        resource>
                    webResources>
                    <warSourceDirectory>src/main/webappwarSourceDirectory>
                    <webXml>src/main/webapp/WEB-INF/web.xmlwebXml>
                configuration>
            plugin>

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

            <profile>
                <id>testid>
                <properties>
                    test
                        ……
                properties>
            profile>
            <profile>
                <id>devid>
                <properties>
                    dev
                        ……
                properties>
            profile>    

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

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

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

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