多Profile文件配置方式

在企业实际开发中,环境通常都有多个 ,如开发环境、测试环境、仿真环境、线上环境。不一样环境的须要参数都是不同的,好比数据库链接信息、redis服务器地址等,这时候就须要配置不一样环境的配置。 1.yml多文档块方式
[Java] 纯文本查看 复制代码
?
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107java

默认配置,若是没有指定profiles,则默认配置生效

logging:
level:mysql

cn.itcast: debug
org.springframework: debug

spring:
datasource:redis

driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/springboot
username: root
password: 123456

mybatis:
configuration:spring

#查看运行Sql
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# mapper.xml文件位置,若是没有映射文件,请注释掉
mapper-locations: classpath:mappers/*.xml
person:
name: 小姐姐2
age: 18
mary: false
birthday: 2001/03/27
hobby:sql

- 王者荣耀
- 吃鸡
- 看片

sanwei: {height: 177cm,weight: 50cm, bust: 65cm }
cat:数据库

name: 小花2
age: 3

server:
port: 80apache


dev开发环境配置

logging:
level:springboot

cn.itcast: debug
org.springframework: debug

spring:
datasource:服务器

driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/springboot
username: root
password: 123456

profiles: dev #指定属于dev开发环境
mybatis:
configuration:mybatis

#查看运行Sql
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# mapper.xml文件位置,若是没有映射文件,请注释掉
mapper-locations: classpath:mappers/*.xml
person:
name: 小姐姐1
age: 18
mary: false
birthday: 2001/03/27
hobby:

- 王者荣耀
- 吃鸡
- 看片

sanwei: {height: 177cm,weight: 50cm, bust: 65cm }
cat:

name: 小花1
age: 4

server:
port: 8081


test测试环境配置

logging:
level:

cn.itcast: debug
org.springframework: debug

spring:
datasource:

driverClassName: com.mysql.jdbc.Driver
url: jdbc:mysql://127.0.0.1:3306/springboot
username: root
password: 123456

profiles: test #指定属于测试环境
mybatis:
configuration:

#查看运行Sql
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

# mapper.xml文件位置,若是没有映射文件,请注释掉
mapper-locations: classpath:mappers/*.xml
person:
name: 小姐姐2
age: 18
mary: false
birthday: 2001/03/27
hobby:

- 王者荣耀
- 吃鸡
- 看片

sanwei: {height: 177cm,weight: 50cm, bust: 65cm }
cat:

name: 小花2
age: 3

server:

port: 8082

启用环境

spring:
profiles:

active: dev

2 .多Profile文件方式
咱们在主配置文件编写的时候,文件名能够是 application-{profile}.properties/yml

3 .激活指定profile 一、在配置yml文件中指定 spring.profiles.active=dev 二、命令行: java -jar spring-boot-02-config-0.0.1-SNAPSHOT.jar --spring.profiles.active=dev; 能够直接在测试的时候,配置传入命令行参数三、虚拟机参数; -Dspring.profiles.active=dev

相关文章
相关标签/搜索