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

  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>

 

相关文章:

  • 2021-12-24
  • 2021-12-27
  • 2021-07-04
  • 2021-04-26
  • 2022-01-30
  • 2022-01-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2021-06-20
  • 2021-03-27
  • 2022-01-19
  • 2021-05-31
相关资源
相似解决方案