一、yml版
1、application.yml
spring:
profiles:
active: prod
2、application-dev.yml
server:
port: 8080
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC
username: 账号
password: 密码
#放到单独文件的数据源和连接池
#profiles:
#active: druid
thymeleaf:
cache: true
pagehelper:
auto-dialect: mysql
reasonable: true
# 日志配置
logging:
level:
com.example: info
# 打印出sql语句
com.example.mapper: debug
org.springframework: warn
3、application-prod.yml
server:
port: 80
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
url: jdbc:mysql://localhost:3306/数据库名?serverTimezone=UTC
username: 账号
password: 密码
#放到单独文件的数据源和连接池
#profiles:
#active: druid
thymeleaf:
cache: false
pagehelper:
auto-dialect: mysql
reasonable: true
# 日志配置
logging:
level:
com.example: info
# 打印出sql语句
com.example.mapper: debug
org.springframework: warn
4、application-durid.yml 将数据库连接和连接池配置单独放到一个文件
# 数据源配置
spring:
datasource:
type: com.alibaba.druid.pool.DruidDataSource
driverClassName: com.mysql.cj.jdbc.Driver
druid:
# 主库数据源
master:
url: jdbc:mysql://localhost:3306/ry?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
username: root
password: root
# 从库数据源
slave:
# 从数据源开关/默认关闭
enabled: false
url:
username:
password:
# 初始连接数
initialSize: 5
# 最小连接池数量
minIdle: 10
# 最大连接池数量
maxActive: 20
# 配置获取连接等待超时的时间
maxWait: 60000
# 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
timeBetweenEvictionRunsMillis: 60000
# 配置一个连接在池中最小生存的时间,单位是毫秒
minEvictableIdleTimeMillis: 300000
# 配置一个连接在池中最大生存的时间,单位是毫秒
maxEvictableIdleTimeMillis: 900000
# 配置检测连接是否有效
validationQuery: SELECT 1 FROM DUAL
testWhileIdle: true
testOnBorrow: false
testOnReturn: false
webStatFilter:
enabled: true
statViewServlet:
enabled: true
# 设置白名单,不填则允许所有访问
allow:
url-pattern: /druid/*
# 控制台管理用户名和密码
login-username:
login-password:
filter:
stat:
enabled: true
# 慢SQL记录
log-slow-sql: true
slow-sql-millis: 1000
merge-sql: true
wall:
config:
multi-statement-allow: true
二、properties版
1、application.properties
name=这是默认配置文件
spring.profiles.active=prod
2、application-dev.properties
name=这是开发环境配置文件
server.port=8080
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://12.132.1.71:3306/test?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
# thymeleaf配置,开发环境不启用缓存,正式环境下请启用缓存,提高性能
spring.thymeleaf.cache=false
# thymeleaf对html元素格式要求严格,设置它的mode为HTML,忘记结束标签后不会报错
spring.thymeleaf.mode=HTML
# 如果要在mapper.xml里使用model,不加此项要写完整路径com.....model...
mybatis.type-aliases-package=com.springboot.pagehelper.model
# 如果要将mapper的xml文件放在 resources目录下,对mybatis 进行如下配置
mybatis.mapper-locations=classpath:mapper/*.xml
3、applicationprod.properties
name=这是生产环境配置文件
server.port=80
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://11.122.1.71:3306/test?useUnicode=true&characterEncoding=UTF8&useSSL=false&serverTimezone=UTC
spring.datasource.username=root
spring.datasource.password=root
# thymeleaf对html元素格式要求严格,设置它的mode为HTML,忘记结束标签后不会报错
spring.thymeleaf.mode=HTML
# 如果要在mapper.xml里使用model,不加此项要写完整路径com.....model...
mybatis.type-aliases-package=com.springboot.pagehelper.model
# 如果要将mapper的xml文件放在 resources目录下,对mybatis 进行如下配置
mybatis.mapper-locations=classpath:mapper/*.xml
4、打完jar包后用jar命令修改配置文件
java -jar PropertiesSpringBoot-0.0.1-SNAPSHOT.jar --spring.profiles.active=test