springBoot專案中,如何根據不同的環境,打包不同的配置檔案
阿新 • • 發佈:2018-12-27
版權宣告:轉發請註明,謝謝配合 https://blog.csdn.net/qq_31289187/article/details/85116371
1、建立springboot專案,然後建立不同的resource
2、application.properties加上一個標誌,方便測試
3、在pom.xml中定義全域性配置資訊
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version >2.1.1.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cn.dl</groupId>
<artifactId>springboot-maven-package-demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springboot-maven-package-demo</ name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<!--定義全域性的配置資訊-->
<profiles>
<profile>
<id>dev</id> <!--開發環境-->
<properties>
<deploy.type>dev</deploy.type>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>pro</id> <!--生產環境-->
<properties>
<deploy.type>pro</deploy.type>
</properties>
</profile>
<profile>
<id>pre_pro</id> <!--預生產環境-->
<properties>
<deploy.type>pre_pro</deploy.type>
</properties>
</profile>
</profiles>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<!--deploy.type 指定部署型別:dev、pre_pro、pro-->
<directory>src/main/resources.${deploy.type}</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
4、打包測試
1、使用命令:mvn clean package -P
引數
p:就是前面定義的profiles檔案,-p後面的引數就是profile中配置的id值
例如執行命令:
F:\ideaWorkSpace\practice\springboot-maven-package-demo>mvn clean package -Ppro
作者:燕少江湖
來源:CSDN
原文:https://blog.csdn.net/qq_31289187/article/details/85116371
版權宣告:本文為博主原創文章,轉載請附上博文連結!