maven spring profile 協同

  請在網上查相關的使用情景,這裏直接上要點。另外,可能不僅一種方法,但這裏只有一種。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>
相關文章
相關標籤/搜索