0

I'm trying to add authorization to several microservices. Given all the services share similar authorization process, I want to extract the logic to a shared library.

I managed to create library, but I realise all the configurations need to be set in the application.yml file in the microservice which calls the library. I don't want to expose some of the configurations at service layer though.

After some searches, I found I could set @PropertySource("library.properties") in my library's configuration class to force reading properties from the specified .properties file within the library.

The problem now is I want to set different values for different environments, e.g. authorization URL for test and production would be different. How can I configure the file so that the configuration class would read same property value based on active profile (e.g. environment = test/staging/production)?

Garis M Suero
  • 7,974
  • 7
  • 45
  • 68
xialin
  • 7,686
  • 9
  • 35
  • 66
  • For the record, I end up defining `application-{env}.properties` file in the Java library repo. And it can be picked up correctly by the service that uses it. – xialin Jul 23 '20 at 23:11

1 Answers1

0

You can have multiple property files such as "application-environment.yml” in your resource folder. Spring framework picks the right one based on the active profile. For example, if you define a “staging” environment and have a staging profile and then your property file should be named as application-staging.yml.

Ravi Sharma
  • 160
  • 4