Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/394.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/8/design-patterns/2.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应用程序上下文xml文件中使用几个参数调用java方法_Java_Spring_Spring Mvc_Applicationcontext - Fatal编程技术网

如何在spring应用程序上下文xml文件中使用几个参数调用java方法

如何在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

我尝试配置我的spring应用程序。 我需要这样定义属性占位符:

<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源代码中找到了它。感谢您提供了这个简单明了的解决方案。