我尝试配置我的 spring 应用程序。 我需要像这样定义属性占位符:
<context:property-placeholder
location="classpath:ov.properties,file:#{appServerUrl.replaceFirst('regexp','')}/test.properties"
ignore-resource-not-found="true" />
但结果是 org.springframework.expression.ParseException: Expression 'file:#{appServerUrl.replaceFirst(''' @ 5: No ending suffix '}' for expression starting at character 5
如果我仅使用一个参数或不使用参数调用 java 方法,它都可以正常工作。怎么了?谢谢你的回复。
最佳答案
<context:property-placeholder/>
的解析器元素首先拆分 location
的值属性使用 StringUtils.commaDelimitedListToStringArray(String)
.这就是将您的第二个位置一分为二的原因。
为了避免这种情况,您可以定义一个 String
具有第二个位置值的 bean:
<bean name="testPropertiesLocation" class="java.lang.String">
<constructor-arg value="file:#{appServerUrl.replaceFirst('regexp','')}/test.properties" />
</bean>
然后像这样使用它:
<context:property-placeholder
location="classpath:ov.properties,#{testPropertiesLocation}"
ignore-resource-not-found="true" />
关于java - 如何在 spring 应用程序上下文 xml 文件中调用带有几个参数的 java 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31468414/