S
S
Samvel Ayvazyan2019-08-21 20:05:54
Java
Samvel Ayvazyan, 2019-08-21 20:05:54

How to read from the key the value of one application.properties value from the key of the second application.properties?

Hello everyone
Let's say we have two files application.properties and token.properties.
Token.properties has a key named "token" and its value is "123".
Click on the spoiler "token.properties"

token properties
token=123

Application.properties also has a key called "token", but its value is a reference to the "token" key in the "application.properties" file.
Approximate view - click on the spoiler "application.properties":
application.properties
token=${/src/main/resources/token.properties:${token}}

But in fact, if you compile the code with the prescribed line, as in the last spoiler, you will get a compilation error, due to incorrect writing of the value of the "token" key in the "token.properties" file.
Question: is it possible to do this, and if so, how to correctly write the value as a link to the key of a certain file?
P. S> There was another attempt to write as follows, without the desired result (similarly, you can write the key=value format):
application.properties
token=${/src/main/resources/token.properties:token}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
BorLaze, 2019-08-21
@mr_zadre

What for? What's wrong with @PropertySource?

S
sergey, 2019-08-22
kuzmin @sergueik

hello @mr_zadre
in my opinion if you answer who will read the value from the key of the second application.properties?
and how he gets into the key it will be half the answer (more than half

S
Samvel Ayvazyan, 2019-08-23
@mr_zadre

Thank you all for your help! BorLaze sergey
kuzmin At first I thought to do without @PropertySource and XML altogether, but then I realized that there are no other normal options for the project - so the combination of this annotation and registering token.properties in Spring did the trick.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question