How can I create profiles with spring boot + .yaml?

ip696 :

I have spring boot server with 2 property files: application-local.properties and 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. And I do not understand how can I use profiles with .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

Or I need write all in one application.yaml file? 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

Andrew Tobilko :
  1. Create application.yaml and define all default properties there.
  2. Create application-local.yaml and override properties needed for the local profile.
  3. Create application-test.yaml and override properties needed for the test profile.
  4. Set spring.profiles.active by either passing it as a system property (-D for java) or defining it within application.yaml.

When you are running an app with a {PROFILE}, Spring will parse application-{PROFILE}.yaml after application.yaml.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=75755&siteId=1