Spring boot Maven project package
Maven multi-use test dev prod environment package
Structure of the project
In the following figure it is seen that the individual packing environment we need to be separated using application- environment .yml are named
Environment Configuration start
First, we need to configure spring.profiles.active = @ profileActive @ here in application.yml file proofileAction are we to use the following variables
spring:
profiles:
active: @profileActive@
pom.xml
We need to specify the name finalname in pom, of course, the name does not affect the packaging for it.
In fact you do not configure resources node is also possible, just to add a few less in the package configuration file in pom.
Of course, you can choose which files you want to import by include.
< Build > < plugins > < plugin > < the groupId > org.springframework.boot </ the groupId > < the artifactId > Spring-Boot-Maven-plugin </ the artifactId > </ plugin > </ plugins > <-! Rear package file name: project name - environment - version -> < finalName > $ {project.artifactId} - $ {profileActive} - $ {project.version} </ finalName > < Resources > <resource> < Directory > src / main / Resources </ Directory > <-! Open filter replacement function -> < Filtering > to true </ Filtering > < Includes > <-! Item packaged complete package contains only the files the current environment - -> < the include > application.yml </ the include > < the include > file application -} $ {profileActive .yml </ the include > </ Includes > </ Resource > </resources> </Build > <-! multi-environment configuration program -> < Profiles > < Profile > < the above mentioned id > dev </ the above mentioned id > < the Properties > < profileActive > dev </ profileActive > </ the Properties > < Activation > <-! Default dev development using the case does not include configuration parameters, such as packaged -p -> < activeByDefault > to true </ activeByDefault > </ Activation > </profile> <!-- 打包命令package -P test --> <profile> <id>test</id> <properties> <profileActive>test</profileActive> </properties> </profile> <!-- 打包命令package -P prod --> <profile> <id>prod</id> <properties> <profileActive>prod</profileActive> </properties> </profile> </profiles>
In the pom profiles node is the sub-critical items packaged, dynamically updated to our configuration values in application.xml during packaging by node profile
When you compile the project, you can use the -P parameter to specify the profile you want to use the id, for example, the following command will use the dev profile:
mvn clean package -P dev
If you want to use the test, only need to be changed to the following
mvn clean package -Ptest
If you do not specify -P argument, a activeByDefault = true (i.e. dev) is used.
Original: https://blog.csdn.net/qq_22327273/article/details/83548138
Reference documents: