0

I have a configuration property that needs to be sent to another system as part of a post body.

lets say for example if have an application.properties file with

my.property.raw=${parameter:some-identifier}

I also have a @ConfigurationProperties annotated class that might look like this

@ConfigurationProperties(prefix = "my.property")
public class Properties {
    private String raw;
    
    // getters and such
}

The problem i have is that Spring will see ${parameter:some-identifier} and immediately assumes i want it to be injected with a property names "parameter" and if its not there, put "some-identifier". i have tried to set the property to ${parameter:${parameter:some-identifier}} but Spring seems to have accounted for recursive property injection and it still comes out as "some-identifier".

I know i can write some code around that and replace the ":" with something else and change it back after the fact but i'm trying to make this work without any code change.

So in summation, Spring boot sees this as a configuration property ${parameter:some-identifier} upon injection into the ConfigurationProperties annotated class, the value ends up being some-identifier. What i want to happen is the value in the Properties class after Spring does its variable replacement process is ${parameter:some-identifier} as this injectable format of a value is intended for a down stream system that is expecting that format. Preferably, without changing any code. Maybe there is some special formatting i can use to tell spring to ignore this specific property.

Thanks for your time! and yes i realize this is probably the opposite of what people normally want from Spring.

shindu
  • 1
  • 3
  • sorry i couldn't get your question, can you update the post with actual output & expected output ? – Ryuzaki L Feb 19 '21 at 16:12
  • 1
    Is this a dupe? https://stackoverflow.com/questions/13162346/escape-property-reference-in-spring-property-file – Kayaman Feb 19 '21 at 16:40
  • It could be, trying some of those solutions. – shindu Feb 19 '21 at 18:36
  • Does this answer your question? [Escape property reference in Spring property file](https://stackoverflow.com/questions/13162346/escape-property-reference-in-spring-property-file) – SatheeshJM Jun 19 '21 at 15:08

1 Answers1

0

As stated by @Kayaman this is indeed a duplicate of Escape property reference in Spring property file

The solution i pulled from there, with some modification, was this:

${dollar:$}{parameter:some-identifier}

https://stackoverflow.com/a/48897422/4621716

I did this because i also don't have control over the process that is generating that application.properties beyond changing existing values.

I hope this helps and i wish i could give @Kayaman credit for pointing me in the right direction but i guess i'll accept my own answer. Thanks.

shindu
  • 1
  • 3