Giter Club home page Giter Club logo

multiple-yml-sample's Introduction

Spring Boot Sample

  • As of Spring Boot version 2.0.0.M7(2017-12-17)

  • multiple config files for each environment

  • config files

app-key-{environment}.yml

environment default local prod
key val-default
key1 val1-default val1-local
key2 val2-default val2-prod

app-api-{environment}.yml

environment default local prod
timeout 3
retry-count 1 5 3

If you use the below parameter

--spring.profiles.active=local

then you can get value from config file , depends on envisonment

*** app-key-config:key=[val-default] key1=[val1-local] key2=[val2-default] *** app-api-config:timeout=[3] retryCount=[5]

If you use the prod parameter

--spring.profiles.active=prod
*** app-key-config:key=[val-default] key1=[val1-default] key2=[val2-prod] *** app-api-config:timeout=[3] retryCount=[3]

There are config files like below

└── resources
├── application.yml
└── config
  ├── app-api-local.yml
  ├── app-api-prod.yml
  ├── app-api.yml
  ├── app-key-local.yml
  ├── app-key-prod.yml
  └── app-key.yml

I use @PropertySource to each config file

  • AppKeyConfig.java
@Configuration
@EnableConfigurationProperties
@PropertySource({"classpath:/config/app-key.yml","classpath:/config/app-key-${spring.profiles.active}.yml"})
@ConfigurationProperties
public class AppKeyConfig {
  private String key;
  private String key1;
  private String key2;
...
  • AppApiConfig.java
@Configuration
@PropertySource({"classpath:/config/app-api.yml","classpath:/config/app-api-${spring.profiles.active}.yml"})
@ConfigurationProperties
public class AppApiConfig {
  private int timeout;
  private int retryCount;
...

multiple-yml-sample's People

Contributors

tomotaka01 avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.