如何在spring应用程序上下文xml文件中使用几个参数调用java方法
我尝试配置我的spring应用程序。 我需要这样定义属性占位符:如何在spring应用程序上下文xml文件中使用几个参数调用java方法,java,spring,spring-mvc,applicationcontext,Java,Spring,Spring Mvc,Applicationcontext,我尝试配置我的spring应用程序。 我需要这样定义属性占位符: <context:property-placeholder location="classpath:ov.properties,file:#{appServerUrl.replaceFirst('regexp','')}/test.properties" ignore-resource-not-found="true" /> <context:property-placehold
<context:property-placeholder
location="classpath:ov.properties,file:#{appServerUrl.replaceFirst('regexp','')}/test.properties"
ignore-resource-not-found="true" />
<context:property-placeholder
location="classpath:ov.properties,#{testPropertiesLocation}"
ignore-resource-not-found="true" />
但在结果中,我有org.springframework.expression.ParseException:expression'文件:#{appServerUrl.replaceFirst(''@5:无结尾后缀'}用于从字符5开始的表达式
如果我只使用一个参数或不使用参数调用java方法,它会正常工作。有什么问题吗?谢谢您的回复。元素的解析器首先使用StringUtils.commadelimitedListToStringaray(String)拆分location
属性的值
。这就是is将第二个位置一分为二的原因
为了避免这种情况,可以使用第二个位置的值定义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,file:#{appServerUrl.replaceFirst('regexp','')}/test.properties"
ignore-resource-not-found="true" />
<context:property-placeholder
location="classpath:ov.properties,#{testPropertiesLocation}"
ignore-resource-not-found="true" />
调试了几个spring类后,我发现replaceFirst(“”,“,”)
方法参数之间的逗号字符破坏了解析。spring在两个位置将其分开“文件:{appServerUrl.replaceFirst('regexp')
和““”)}/test.properties”
创建或销毁bean时,您可以使用init method和destroy method调用方法。是的,我在Spring源代码中找到了它。感谢您提供了这个简单明了的解决方案。