jaudo
jaudo

Reputation: 2122

Skip Spring placeholder substitution

I'm using Spring properties placeholders in my application. One of my properties values contains something Spring interprets as a placeholder, but I don't want it:

@Value("${propertyName}")
private String property;

My property is well defined:

propertyName=Welcome ${name}

Without surprise I get an error :

Could not resolve placeholder 'name' in value "Welcome ${name}"

propertyName is something I want to interpret myself, so I don't want ${name} to be resolved by Spring. Is this possible?

Upvotes: 4

Views: 729

Answers (2)

pvpkiran
pvpkiran

Reputation: 27068

You need to escape dollar ($) in that case. So that spring doesn't treat this as a property.

propertyName=Welcome #{'$'}{name}

Upvotes: 6

yvoytovych
yvoytovych

Reputation: 871

You could create your own PropertySourcesPlaceholderConfigurer bean and set ignoreUnresolvablePlaceholders as true, this should work. But keep in mind that this will affect all placeholders in that context.

Upvotes: 0

Related Questions