[英]How can I create profiles with spring boot + .yaml?
I have spring boot server with 2 property files: application-local.properties
and application-test.properties
我有带有 2 个属性文件的 Spring Boot 服务器:
application-local.properties
和application-test.properties
In each file I have configs for dev machine and for test.在每个文件中,我都有用于开发机器和测试的配置。 Start it like this:
像这样开始:
-Dspring.profiles.active=local
But in new spring boot project I use .yaml
config file.但是在新的 Spring Boot 项目中,我使用了
.yaml
配置文件。 And I do not understand how can I use profiles
with .yaml
.而且我不明白如何将
profiles
与.yaml
一起.yaml
。 I tried read documentation but understood nothing.我尝试阅读文档,但什么也不懂。 Can you explain what to do, step by step?
你能一步一步解释该怎么做吗?
I need have two files?我需要两个文件?
application-local.yaml
and application-test.yaml
application-local.yaml
和application-test.yaml
Or I need write all in one application.yaml
file?或者我需要在一个
application.yaml
文件中写入所有内容? If in one file how can I separate configs?如果在一个文件中,我如何分离配置? It is my config:
这是我的配置:
server:
path: ***
port: ***
cxf:
path: ***
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: oracle.jdbc.OracleDriver
url: ***
username: ***
password: ***
hikari:
minimumIdle: 5
maximumPoolSize: 20
idleTimeout: 30000
poolName: SpringBootJPAHikariCP
maxLifetime: 2000000
connectionTimeout: 30000
connection-test-query: SELECT 1 FROM DUAL
spring.jpa:
show-sql: false
database-platform: org.hibernate.dialect.Oracle10gDialect
properties.hibernate.jdbc.batch_size: 30
properties.hibernate.cache.use_second_level_cache: false
hibernate:
ddl-auto: validate
spring.cache:
ehcache:
config: classpath:ehcache.xml
#app configs
my:
messages-max-count: 5
messages-delay: 100
schedulers-charge-delay: 100
client:
first-server-address: ***
second-server-address: ***
last-server-address: ***
enabled-client: FirstClient
I want create test profile and change database url (or change to postgreSql), change maximumPoolSize
property我想创建测试配置文件并更改数据库 url(或更改为 postgreSql),更改
maximumPoolSize
属性
application.yaml
and define all default properties there.application.yaml
并在那里定义所有默认属性。application-local.yaml
and override properties needed for the local
profile.application-local.yaml
并覆盖local
配置文件所需的属性。application-test.yaml
and override properties needed for the test
profile.application-test.yaml
并覆盖test
配置文件所需的属性。spring.profiles.active
by either passing it as a system property ( -D
for java
) or defining it within application.yaml
.spring.profiles.active
作为系统属性( -D
用于java
)传递或在application.yaml
定义它来设置spring.profiles.active
。 When you are running an app with a {PROFILE}
, Spring will parse application-{PROFILE}.yaml
after application.yaml
.当您运行带有
{PROFILE}
的应用程序时,Spring 将在application.yaml
之后解析application-{PROFILE}.yaml
。
Yes, you can create multiple profiles even with single file Profile are separated with 3 DASH ( --- )是的,即使使用单个文件,您也可以创建多个配置文件配置文件用 3 个 DASH ( --- ) 分隔
logging:
level:
.: error
org.springframework: ERROR
spring:
profiles:
active: "dev"
main:
banner-mode: "off"
server:
port: 8085
---
spring:
profiles: dev
---
spring:
profiles: prod
I have spring boot server with 2 property files: application-local.properties
and application-test.properties
我有带有2个属性文件的spring boot服务器:
application-local.properties
和application-test.properties
In each file I have configs for dev machine and for test.在每个文件中,我都有用于开发机和测试的配置。 Start it like this:
像这样启动它:
-Dspring.profiles.active=local
But in new spring boot project I use .yaml
config file.但是在新的春季启动项目中,我使用
.yaml
配置文件。 And I do not understand how can I use profiles
with .yaml
.而且我不明白如何将
.yaml
与profiles
一起.yaml
。 I tried read documentation but understood nothing.我尝试阅读文档,但一无所知。 Can you explain what to do, step by step?
您能一步一步解释什么吗?
I need have two files?我需要两个文件吗?
application-local.yaml
and application-test.yaml
application-local.yaml
和application-test.yaml
Or I need write all in one application.yaml
file?还是我需要将所有内容都写在一个
application.yaml
文件中? If in one file how can I separate configs?如果在一个文件中,如何分隔配置? It is my config:
这是我的配置:
server:
path: ***
port: ***
cxf:
path: ***
spring.datasource:
type: com.zaxxer.hikari.HikariDataSource
driver-class-name: oracle.jdbc.OracleDriver
url: ***
username: ***
password: ***
hikari:
minimumIdle: 5
maximumPoolSize: 20
idleTimeout: 30000
poolName: SpringBootJPAHikariCP
maxLifetime: 2000000
connectionTimeout: 30000
connection-test-query: SELECT 1 FROM DUAL
spring.jpa:
show-sql: false
database-platform: org.hibernate.dialect.Oracle10gDialect
properties.hibernate.jdbc.batch_size: 30
properties.hibernate.cache.use_second_level_cache: false
hibernate:
ddl-auto: validate
spring.cache:
ehcache:
config: classpath:ehcache.xml
#app configs
my:
messages-max-count: 5
messages-delay: 100
schedulers-charge-delay: 100
client:
first-server-address: ***
second-server-address: ***
last-server-address: ***
enabled-client: FirstClient
I want create test profile and change database url (or change to postgreSql), change maximumPoolSize
property我想创建测试配置文件并更改数据库URL(或更改为postgreSql),更改
maximumPoolSize
属性
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.