The maven profile integrates the spring profile method

1. Add resource points to build-resources-resource in POM

<build>
        <finalName>lx-service</finalName>
        <resources>
            <resource>
                <directory>src/main/resources</directory>
                <filtering>true</filtering>
            </resource>
        </resources>
...
</build>

 

2. Add war packaging plugin configuration to build-plugins-plugin in POM

<!-- war packaging plugin, set the war package name without version number -->
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-war-plugin</artifactId>
    <configuration>
        <webResources>
            <resource>
                <filtering>true</filtering>
                <directory>src/main/resources/profile</directory>
                <targetPath>WEB-INF</targetPath>
                <includes>
                    <include>**/web.xml</include>
                </includes>
            </resource>
        </webResources>
    </configuration>
</plugin>

 3. Add web.xml under src/main/resources/profile, which can use the variables defined by maven profiles

<!-- Set the default Profile of Spring Context -->
<context-param>
    <param-name>spring.profiles.default</param-name>
    <param-value>${mvn.spring.profile}</param-value>
</context-param>

 4. The value will be automatically modified when packaging.

5. Note that spring.profiles in src/main/webapp/WEB-INF/web.xml are still read when developing locally.

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326104826&siteId=291194637