application.yml
spring:
profiles:
active: @profileActive@
datasource:
driver-class-name: com.mysql.jdbc.Driver
type: com.alibaba.druid.pool.DruidDataSource
initialSize: 1
maxActive: 20
minIdle: 3
maxWait: 60000
timeBetweenEvictionRunsMillis: 60000
minEvictableIdleTimeMillis: 300000
validationQuery: SELECT 'x'
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
poolPreparedStatements: true
maxPoolPreparedStatementPerConnectionSize: 20
#配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
#filters: stat,wall,slf4j
#通过connectProperties属性来打开mergeSql功能;慢SQL记录
#connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
jpa:
properties:
hibernate:
hbm2ddl:
auto: update
#update级别会根据bean创建/更新表结构
---
spring:
profiles: dev
datasource:
url: jdbc:mysql://localhost:3306/dbName?allowMultiQueries=true&useSSL=false
username: root
password:
---
spring:
profiles: test
datasource:
url: jdbc:mysql://localhost:3306/dbName?allowMultiQueries=true&useSSL=false
username: root
password:
---
spring:
profiles: prod
datasource:
url: jdbc:mysql://localhost:3306/dbName?allowMultiQueries=true&useSSL=false
username: root
password:
---
注意:
1、value前面的冒号后面要带空格
2、缩进使用空格而不要用制表符
pom.xml
<profiles>
<profile>
<id>dev</id>
<properties>
<profileActive>dev</profileActive>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
</profile>
<profile>
<id>test</id>
<properties>
<profileActive>test</profileActive>
</properties>
</profile>
<profile>
<id>prod</id>
<properties>
<profileActive>prod</profileActive>
</properties>
</profile>
</profiles>
run:
运行Application.class 可设置Program arguments:--spring.profiles.active=prod
build:
mvn clean package -Dmaven.test.skip=true -P prod
网友评论