0

I am trying to externalize the properties file of my project to pick up placeholder values from outside of the jar

Steps to run:

  1. Created a jar file without application.properties file.

  2. Have certain placeholder variables defined in application-dev.properties for the profile to pick up . For ex :

    server.api.url=

    spring.profiles.active=

  3. Run the script file from shell script :

    #!/bin/ksh

    API_URL = ${HOME}/cc_home/tools/cc-tool --string='${cc:app/server.api.url}'

    export server.api.url=$API_URL

    java -jar wink-tool.jar --spring.profiles.active=dev

    echo "END"

It is failing with :

bash: export: `server.api.url=localhostxx': not a valid identifier

As i read

man bash

I get that , "name A word consisting only of alphanumeric characters and underscores, and beginning with an alphabetic character or an underscore. Also referred to as an identifier."

How to now achieve this, to read the properties from Shell script to set up the externalised property defined in application-dev.properties outside the jar, which reads/provide value from the identifiers defined in shell script to deploy the exported configuration during sprinboot jar run?

Ranjit M
  • 138
  • 4
  • 4
  • 17

1 Answers1

0

Why do you need to configure the host? Shouldn't you use the server port instead? anyway, you need to export the API_HOST=value , with "export" you are trying to set an env variable to be used inside spring. "server.api.host" is not valid name for env variable.

In your Spring properties file you will have:

server.api.host=${API_HOST}

and when running will take the value from the one you set in the terminal with your

export API_HOST=value

So just remember, in order to get an environment value from your properties you need to follow this

property=${SOME_ENV_VARIABLE_IDENTIFIER}
OctavioCega
  • 166
  • 2
  • 15
  • So you meant to say, I should change the placeholders defined in my application from . to _ , & then subsequently change identifiers inside shell script as, "_" which will setup the properties files during jar run? If this is YES, it is tedious task, as i have many placeholders where it is defined like "." in between. API_HOST is just an example, and there are many placeholders like this which i wanted to call up from consul, as those are decrypted values to be put inside application properties when spring application runs. FYI :: https://dzone.com/articles/spring-boot-project-set-up – Ranjit M Feb 19 '21 at 07:38
  • Yes you need to add a place holder for each property set in your application.properties that you want to set via Env Variables. In practice is a good thing because you will have defined every property independently. Also in IDEs like IntelliJ you can easily set them in the Run configurations and even have different set of env values – OctavioCega Feb 19 '21 at 07:41
  • In Bw, updated the post to take correct example. We are not talking in reference of env variables defined in bash language, want to set up application level properties for springboot project. – Ranjit M Feb 19 '21 at 07:42
  • If you need to have an external file with all the properties instead, I recommend you this https://stackoverflow.com/questions/25855795/spring-boot-and-multiple-external-configuration-files – OctavioCega Feb 19 '21 at 07:44
  • Thanks for the post, but my requirement is bit different. I have to read values from consul, whcih are decrypted and the identifiers defined in shell script encrypts that from consul, which I will use to placards for my placeholders variable defined in application-dev.properties, that is why used : export server.api.url=$API_URL – Ranjit M Feb 19 '21 at 07:50