1

I have a Spring Batch Spring Boot app that needs to be converted to image and later use that in Spring Cloud Data Flow to schedule the job.I have the DEV,UAT,PROD config in

application-properties/dev/application.yml

respectively.We were told to mention the password and username as

password: ${DB_ORCL_PASSWORD}

username: ${DB_ORCL_USER}

I am not sure how the credentials get substituted based on the environment. Is it something i should provide while building the docker image?

GvSharma
  • 2,632
  • 1
  • 24
  • 30
Shravya M
  • 25
  • 1
  • 6
  • Does this answer your question? [Where to set env variables for local Spring Cloud Dataflow?](https://stackoverflow.com/questions/48179824/where-to-set-env-variables-for-local-spring-cloud-dataflow) – Mahmoud Ben Hassine Feb 09 '21 at 12:12
  • @MahmoudBenHassine Thanks for the info, it did help. – Shravya M Mar 05 '21 at 17:31

2 Answers2

0

Create different profiles based on the environment where you specify the different username and password: application-dev.yml, application-uat.yml and application-prod.yml. Each profile can be run by java -jar --spring.profiles.active=<profile>. For more details: https://www.baeldung.com/spring-profiles.

For the image, you can specify the entrypoint using the java command with the profile. See this question: How can I start spring boot application in docker with profile?.

Jiji
  • 1,092
  • 3
  • 15
  • 36
0

Its spring frameworks feature for externalised configuration.

The values in application.properties and application.yml are filtered through the existing Environment when they are used, so you can refer back to previously defined values (for example, from System properties). The standard ${property-value} property-placeholder syntax can be used anywhere within a value.

Note : You need to set environment variables with same property key name in all your environments. Rendering the property values with the values given in environment variables are done by spring. You don't have to worry about that.

Property Placeholders

pvrforpranavvr
  • 2,708
  • 2
  • 24
  • 34