- 配置maven环境
<profiles>
<profile>
<id>dev</id>
<properties>
<package.environment>dev</package.environment>
</properties>
<!-- 是否默认 true表示默认-->
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<package.environment>test</package.environment>
</properties>
</profile>
<profile>
<!-- 生产环境 -->
<id>qa</id>
<properties>
<package.environment>qa</package.environment>
</properties>
</profile>
</profiles>`
- 资源文件
application.yml
spring:
profiles:
active: @package.environment@
application-dev.yml
spring:
datasource:
type: org.springframework.jdbc.datasource.DriverManagerDataSource
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://192.168.20.252/shlaunch?useUnicode=true&characterEncoding=utf-8&useSSL=true&autoReconnect=true
username: shlaunch
password: password
jpa:
database: mysql
show-sql: true
generate-ddl: true
database-platform: org.hibernate.dialect.MySQL5Dialect
hibernate:
ddl-auto: update
server:
port: 8081
logging:
level:
root: info
pattern:
console: '%d{yyyy-MMM-dd HH:mm:ss.SSS} %-5level [%thread] %logger{15} - %msg%n'
spring:
mvc:
static-path-pattern: /**
线上代码就不贴出来了 都是一样的
3.执行maven勾选中的yml
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>application.yml</include>
<include>application-${package.environment}.yml</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>