基于maven搭建
properties yml格式的配置文件均适用
1:修改总的配置文件 和 开发环境、测试环境、生产环境的配置文件 dev test prod
修改application.yml 注: @activatedProperties@与pom文件中标签对应
#生效配置文件
spring:
profiles:
active: @activatedProperties@
修改application-dev.yml
# 指定端口和后端服务URL
server:
port: 9010
servlet:
context-path: /group_purchasing_server
# 配置连接的数据
spring:
datasource:
url: jdbc:mysql://localhost:3306/dev?tinyInt1isBit=false&serverTimezone=GMT%2B8
username: root
password: 123456
driver-class-name: com.mysql.cj.jdbc.Driver
修改application-test.yml(同application-dev.yml配置)
修改application-prod.yml(同application-dev.yml配置)
2:修改pom.xml文件配置
<profiles>
<profile>
<id>dev</id>
<properties>
<!-- 环境标识,需要与配置文件的名称相对应 -->
<activatedProperties>dev</activatedProperties>
</properties>
<activation>
<!-- 默认环境 -->
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<activatedProperties>test</activatedProperties>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<activatedProperties>prod</activatedProperties>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<jvmArguments>
-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005
</jvmArguments>
<fork>true</fork>
</configuration>
</plugin>
</plugins>
</build>
3:在idea指定开发环境启动和测试环境、生产环境打包时生效的配置文件
指定开发环境生效(默认为开发环境),正常启动即可。
使用idea打包时,指定打包时生效的配置文件,指定apply后,利用工具打包即可。