问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/43493857/could-not-read-properties-if-it-contains-dollar-symbol-var