如果包含美元符号 (${var}),则无法读取属性 [英] Could not read properties if it contains dollar symbol (${var})

查看:106
本文介绍了如果包含美元符号 (${var}),则无法读取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下内容的属性文件:

I have property file with following content:

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

我使用 spring 配置阅读了这个:

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} íåêîððåêòíî çàïîëíåíî èëè ïðîïóùåíî."

我需要 ${fieldName} 因为我想使用 repacer:https://stackoverflow.com/a/3655963/2674303

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

如何避免这个错误?

推荐答案

您应该转义 ${fieldName} 因为它没有定义为 Spring 属性.

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

你可以看看这个问题:spring 属性中的转义属性引用文件和相关的答案.

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

你应该这样写:

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

这篇关于如果包含美元符号 (${var}),则无法读取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆