赞
踩
1、配置文件结构如图
2、修改application.properties
spring.profiles.active= @package.environment@
3、pom.xml配置
- <build>
- <plugins>
- <plugin>
- <!-- springboot编译打包插件-->
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>1.5.9.RELEASE</version>
- <configuration>
- <executable>true</executable>
- </configuration>
- <executions>
- <execution>
- <goals>
- <goal>repackage</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
- </plugins>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- <includes>
- <include>application.properties</include>
- <include>application-${package.environment}.properties</include>
- <include>**/*.xml</include>
- </includes>
- </resource>
- </resources>
- </build>
-
- <profiles>
- <profile>
- <id>dev</id>
- <properties>
- <package.environment>dev</package.environment>
- </properties>
- <!-- 是否默认,true表示默认,默认加载dev配置文件application-dev.properties-->
- <activation>
- <activeByDefault>true</activeByDefault>
- </activation>
- </profile>
- <profile>
- <id>test</id>
- <properties>
- <package.environment>test</package.environment>
- </properties>
- </profile>
- <profile>
- <!-- 生产环境 -->
- <id>prod</id>
- <properties>
- <package.environment>pro</package.environment>
- </properties>
- </profile>
- </profiles>

4、打包命令
- mvn clean package -P dev
-
- mvn clean package -P test
-
- mvn clean package -P pro
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。