Spring Boot支持application.properties和application.yml两种格式的配置文件
- application.properties写法:
#Spring Boot的tomcat默认端口号配置
server.port=8080
#ContextPathtomcat上下文设置
server.servlet.context-path=/myspringboot
#配置日志文件存放路径
logging.file=/Users/puhanjie/Downloads/myspringboot.log
#配置日志级别 debug->info->warn->error->fatal
logging.level.root=info
#是否开启调试模式
debug=true
#配置数据库连接信息
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=root
debug: true
server:
port: 8080
servlet:
context-path: /myspringboot
logging:
level:
root: info
file: /Users/puhanjie/Downloads/myspringboot.log
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost:3306/mydb
username: root
password: root
配置测试环境和生产环境分别使用不同的配置文件
- 首先在application.yml同目录下新建两个名为application-dev.yml和application-prd.yml的配置文件,这两个文件里配置项的写法和application.yml是一样的
- 然后在application.yml文件中写如下配置,修改active的值即可在编译和发布时使用不同环境的配置文件
spring:
profiles:
active: prd