4

I have property file with following content:

INVALID_ARGUMENT=Field ${fieldName} is invalid or missing.

I read this using spring configuration:

@PropertySource("error_messages_en.properties")
@Configuration
public static class ErrorMessagesEn {
     @Value("${INVALID_ARGUMENT}")
    private String invalidArgument;
}

But after application start I see:

Could not resolve placeholder 'fieldName' in value "Ïîëå ${fieldName} íåêîððåêòíî çàïîëíåíî èëè ïðîïóùåíî."

I need ${fieldName} because I want to use repacer: https://stackoverflow.com/a/3655963/2674303

How to avoid this error?

Community
  • 1
  • 1
gstackoverflow
  • 36,709
  • 117
  • 359
  • 710

2 Answers2

3

You should escape ${fieldName} as it is not defined as a Spring property.

You could have a look at this question: Escape property reference in spring property file and the associated answer.

You should write this instead:

INVALID_ARGUMENT=Field #{'$'}{fieldName} is invalid or missing.
Community
  • 1
  • 1
Nicolas Labrot
  • 4,017
  • 25
  • 40
-1

If you are using a yaml file you need to surround the value with quotes

argument: "Field #{'$'}{fieldName} is invalid or missing."