Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/kubernetes/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring消息标记的单引号字符有问题_Spring_Properties_Single Quotes - Fatal编程技术网

Spring消息标记的单引号字符有问题

Spring消息标记的单引号字符有问题,spring,properties,single-quotes,Spring,Properties,Single Quotes,我的资源包中定义了3个属性: test.key1 = Just a normal snippet. test.key2 = snippet with {0} arguments {1}. test.key3 = snippet with 'charac'ter'. test.key4 = snippet with {0} arguments' and 'characters {1}. 以下是我如何在jsp中访问它们: <spring:message code="test.key1"/&g

我的资源包中定义了3个属性:

test.key1 = Just a normal snippet.
test.key2 = snippet with {0} arguments {1}.
test.key3 = snippet with 'charac'ter'.
test.key4 = snippet with {0} arguments' and 'characters {1}.
以下是我如何在jsp中访问它们:

<spring:message code="test.key1"/>
<spring:message code="test.key2" arguments="ARG1,ARG2"/>
<spring:message code="test.key3"/>
<spring:message code="test.key4" arguments="ARG1,ARG2"/>
所以基本上情况是:只要出现
(单引号)字符,参数就不再填充,单引号也不再呈现。有趣的是,当单独应用参数或单引号时,spring没有问题

我能够通过使用2个单引号修复测试场景4,如下所示:

Just a normal snippet.
snippet with ARG1 arguments ARG2.
snippet with 'charac'ter'.
snippet with ARG1 arguments and characters {1}.
test.key4 = snippet with {0} arguments'' and ''characters {1}.
这也正确地呈现了

snippet with ARG1 arguments' and 'characters ARG2.
当然,这是一个维护噩梦:所有包含单引号但没有参数的属性都应该包含1个单引号,而所有包含单引号字符和参数的属性都需要2个单引号


这是为什么?有没有办法修复这种不受欢迎的行为?

显然,这种奇怪的行为是“按设计”的。所有信息汇总在中

要解决这个问题,您可以只在有参数的属性中使用双引号,或者向消息ReSurce bean添加一个附加属性,在这种情况下,所有单引号都必须使用双引号,即使在没有参数的属性中也是如此。这是更加一致的

<property name="alwaysUseMessageFormat" value="true"/>