Integrated maven and Spring boot profile features

Source: Internet
Author: User

Idea: Maven supports the profile feature, when packaged with Maven profile, you can package the specified directory and specify the file, and you can modify the variables in the file. Spring boot also supports the profile feature, as long as you specify SPRING.PROFILES.ACTIVE=XXX in the application.properties file, where xxx is a variable and when MAVEN is packaged, You can modify this variable.

1. Configuring the profile for Maven

< find different profiles!--different environments--<profiles> <profile> <id>dev</id> < Properties> <profiles.active>dev</profiles.active> <maven.test.skip>true</maven.test.skip> </properties> <activation> &LT;ACTIVEBYDEFAULT&G Ttrue</activeByDefault> </activation> </profile> <profile> &LT;ID&G                T;sit</id> <properties> <profiles.active>sit</profiles.active> <maven.test.skip>true</maven.test.skip> </properties> </profile> <profile> &LT;ID&G                T;prd1</id> <properties> <profiles.active>prd1</profiles.active> <maven.test.skip>true</maven.test.skip> <scope.jar>provided</scope.jar> </properties>                </profile> <profile> <id>prd2</id> <properties> <profiles.active>prd2</profiles.active> <maven.test.skip>true</maven.test.skip> <scope.jar>provided</scope.jar> </properties> </profile> </profiles>

Where profiles.active is a variable that we define, can be specified by the MVN command, and can be accessed by others

To configure a modifiable accessible resource file in build

<resources> <resource> <directory>src/main/resources</directory> <filtering>true</filtering> <excludes> <exclude>application-dev.properties</exclud E> <exclude>application-sit.properties</exclude> <exclude>appli                Cation-prd1.properties</exclude> <exclude>application-prd2.properties</exclude> </excludes> </resource> <resource> <directory>src/m Ain/resources</directory> <filtering>true</filtering> <includes> <include>application-${profiles.active}.proper Ties</include> <include>application.properties</include> </includes > </resource> </resources>

Where ${profiles.active} is the variable specified in the above profile

2. Configuring the profile of the Springboot

This is specified by spring.profiles.active

Specify [email protected]@] in application.properties to combine maven with Springboot profile

3. Packaging command: mvn clean package-dmaven.test.skip=true-p prod-e

Integrated maven and Spring boot profile features

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.