0

I have a microservice where I want to have few properties which are environment dependent so I'm using application.yml, and application-dev.yml, application-int.yml etc.....

upon startup I pass spring.profiles.active=myprofile and relevant applicaiton-myprofile.yml gets loaded along with applicaiton.yml. So far everything works fine.

But now I want to categorize some of my non-environment-specific properties into their own business-modules, so ALONG WITH my application.yml applicaiton-.yml I also want to load properties from few more yml files into spring ENVIRONMENT. so I could be able to create create correct BusinessConfigProperties class with @ConfigurationProperties.

To achieve this I tried to add those yml file names in spring.config.location as below

     spring:
          config:
            name:
              - some-props
              - very-different-name-props
            location:
              - classpath:/config/*

I've provided config name too, and all my yml files are present in /config folder

But I'm still unable to read any of the properties mentioned in these file.

I can overcome this by manually loading files with org.yaml.snakeyaml.Yml abut that is too much boilerplate code to read YML map and instantiate my classes. There should be an easy way do achieve this with spring.

UPDATE

I updated above to,

     spring:
          config:
            location:
              - classpath:classpath:/config/some-props.yml,classpath:/config/very-different-name-props.yml

But this also isn't working I'm not using profile, because along with above files, I already have applicaiton-<profile>.yml for environment specific properties. And I will be passig spring.profile.active as environment name in startup jvm arguments. Also I don't want to name these files starting with application-<added_profile>.yml

ThrowableException
  • 1,168
  • 1
  • 8
  • 29
  • That simply won't work as that is not the way to define additional properties to be loaded. Those properties need to be passed in as properties when starting the application with `--spring-config-location=` – M. Deinum Oct 09 '20 at 07:26

1 Answers1

0

maybe just type in your question , it should be spring.profiles.active=myprofile

You can try below try approaches to load multiple files

spring:
  config:
    location: classpath:/config/some-props.yml,classpath:/config/some-Other-props.yml

spring:
  profiles:
    include:
      - CustomPropertiesFile

You can refer to this also https://youtu.be/0G9X-pTv_UU

http://roufid.com/load-multiple-configuration-files-different-directories-spring-boot/

SauriBabu
  • 414
  • 6
  • 15
  • thanks i edited `profileS` typo. But I can not use the profile include solution. my YML file names are not application-.yml they are concrete names. like payment-gateways.yml, batch-apps.yml etc (bad example) . also `spring: config: location: classpath` is also not loading properties. – ThrowableException Oct 09 '20 at 02:52
  • try using spring.config.location in java startup command instead of main application.yml. like this java -jar myproject.jar --spring.config.name=application,conf --spring.config.location=classpath:/external/properties/,classpath:/com/roufid/tutorial. Just go through blog shared by me , you will have better clarity – SauriBabu Oct 09 '20 at 03:04