在SpringBoot框架中,需要配置文件application-xxx.yml,但往往情况下,需要多个配置文件,比如如下:
那SpringBoot启动时到底用哪个配置文件呢?
1.在启动时,会默认加载application.yaml文件,在这个文件中有一个属性是spring.profile.active
这行代表的意思是:指定读取配置文件:dev(开发环境),prod(生产环境),qa(测试环境)
2.以下是部分内容详解
service:
port: 8888 #tomcat服务器的端口号
name: xxxx #应用的名称
server:
port: 10108 #指定端口号启动
spring:
profiles:
active: local #运行哪个环境下的配置文件
cloud:
consul:
host: 127.0.0.1 #consul server的ip地址
port: 8500 #consul运行的端口号
discovery:
register: false #是否将自身服务注册到consul中
datasource:
driver-class-name: com.mysql.jdbc.Driver #mysql的驱动包
url: jdbc:mysql:///jtdb?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true #数据库名称
username: root #数据库的用户名
password: 123456 #数据库的密码
type: xxxxxxxxx #数据库的操作类型
mybatis: #mybatis的配置
configuration:
map-underscore-to-camel-case: true #带有下划线的表字段映射为驼峰式的实体类属性