Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 377 Vote(s) - 3.49 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Spring Boot: How do you specify an environment variable that has dashes in the application.properties?

#1
I have an `application.properties` file that looks like this:

mcl.sso.frontend-url=http://blah.com:9001
mcl.sso.mocking-agent=false

I am trying to override these two variables from the command line. This should be possible by setting environment variables. Here's how I'm running the command:

MCL_SSO_FRONTEND_URL='foobar' MCL_SSO_MOCKING_AGENT='true' ./gradlew run

However, when I print out the values of these variables, `mcl.sso.mocking-agent` equals "true" (as expected), but `mcl.sso.frontend-url` still equals "http://blah.com:9001" (unexpected). Why doesn't `mcl.sso.frontend-url` change the value of the property? I can only assume this has something to do with the way Spring converts environment variables into property keys, but I can't find any specific documentation on this.
Reply

#2
This has been fixed as of Spring Boot `1.2.5`. Previously, you'd have to use `MCL_SSO_FRONTEND-URL` (notice the dash that can't be translated to an underscore).

You can play with bindings using [this sample project](

[To see links please register here]

).
Reply

#3
Just get rid of the dash:

mcl.sso.mocking-agent > MCL_SSO_MOCKINGAGENT

Reply

#4
From [spring-boot documentation][1]:

Binding from Environment Variables
----------------------------------

Most operating systems impose strict rules around the names that can be used for environment variables. For example, Linux shell variables can contain only letters (`a` to `z` or `A` to `Z`), numbers (`0` to `9`) or the underscore character (`_`). By convention, Unix shell variables will also have their names in UPPERCASE.

Spring Boot’s relaxed binding rules are, as much as possible, designed to be compatible with these naming restrictions.

To convert a property name in the canonical-form to an environment variable name you can follow these rules:

- Replace dots (`.`) with underscores (`_`).
- Remove any dashes (`-`).
- Convert to uppercase.

For example, the configuration property `spring.main.log-startup-info` would be an environment variable named `SPRING_MAIN_LOGSTARTUPINFO`.

Environment variables can also be used when binding to object lists. To bind to a `List`, the element number should be surrounded with underscores in the variable name.

For example, the configuration property `my.service[0].other` would use an environment variable named `MY_SERVICE_0_OTHER`.


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through