Skip to main content

Configuring Spring Framework with YAML

Spring application can be configured using YAML as effectively as using properties file. With YAML file one can,

  • Create environment specific profiles

  • Define properties at application level

  • Define (or override) properties at profile level

Spring Framework loads application.yml by default just the way it loads application.properties. If you want to change the name of the yml file you'll have to use context loader to tell what file to look for.

Must knows of the yml based configuration

  1. Profiles - YML supports multiple profiles in a single file. One can define environment specific configurations as profiles in a single file.
  2. Profiles separator - YML configuration file uses 3 dashes (---) to separate a profile. Every property you define after --- is specific to that profile.
  3. Profile name - Give profile a name using spring.config.activate.on-profile property.
  4. Active profile(s) - Define which profile or profiles are active using spring.profiles.active property. More than one profile can be active using comma separated profile names.
  5. Property overriding - If a property is defined more than once in a file, the last occurrence of the property is used. If same property is defined in multiple "active" profiles, last occurrence of the property is used.

E.g.  

In this configuration file,

    • 2 profiles are defined, mongo and marklogic
    • document-writer, batch-size, number-of-documents and document-format properties are common to both profiles
    • database property is defined differently for each profile
    • host property is available only to marklogic profile. Attempting to use host property when marklogic profile is not active will result in an error. 

Comments

  1. Wynn casino: How to play, get a no deposit bonus
    The Wynn buffet is an excellent spot for those seeking a Vegas experience, 인천광역 출장샵 and its 전라남도 출장샵 menu is superb. 당진 출장마사지 The buffet 충주 출장샵 has a 오산 출장샵 wide variety of

    ReplyDelete
  2. Thank you for sharing your diary featuring the spring framework. We can opt this out earlier with the help of CAD drawing Services.It is impressive to see your works.

    ReplyDelete

Post a Comment

Popular posts from this blog

Multi threading in SpringBoot Application

How I got my SpringBoot application to execute a service in multiple threads Enabled SpringBoot application run Async tasks Defined a service method which can be invoked asynchronously and returns CompletableFuture object as required by Spring Let Spring manage service component instance Though not required, configured TaskExecutor Spring could use Enable SpringBoot application to run tasks asynchronously To be able to execute tasks using multiple threads asynchronously SpringBoot application must be annotated with @EnableAsync .   I defined this annotation right after   @SpringBootApplication . @SpringBootApplication @EnableAsync public class NosqlApplication implements CommandLineRunner { Logger logger = LoggerFactory. getLogger (NosqlApplication. class ) ; Aync service method returning CompletableFuture object Spring could invoke tasks synchronously and asynchronously. To be able to invoke tasks asynchronously (and let main thread do other things) I annotated the servic...

Install Citrix Workspace on Groovy Gorilla on Raspeberry Pi

  How I got Citrix Workspace working on Groovy Gorilla (Ubuntu 20.10) on Raspberry Pi 400 At first installing Citrix on Ubuntu may seem like a no brainer, but because how Ubuntu and Citrix have packaged software for Raspberry Pi, it is pain in the neck to get it working correctly.  What is the issue? When I installed Ubuntu on Raspberry Pi hardware, t he only package available for Pi 4/400 was 64 bit, but Citrix has  only ARMHF packages for raspberry Pi which is 32 bit. Technically 32 bit package should work on 64 bit architecture without a fuss, but for whatever reason Citrix package checks if package to be installed matches OS bit level. Attempting to install the package as well as subsequent system updates report failure. More over Software Center can't install or remove software complaining broken packages on the system. First let me tell you how I installed Citrix then will go on fixing issue. Prepare system for Citrix installation Check system architecture usi...