在spring xml配置中连接字符串

rou*_*ble 9 java spring spring-ws cxf jax-ws

我需要将spring bean的字符串值连接到现有字符串,然后将其设置为另一个bean的属性:

<bean id="inet" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetClass"><value>java.net.InetAddress</value></property>
    <property name="targetMethod"><value>getLocalHost</value></property>
</bean>
<bean id="host" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject"><ref local="inet"/></property>
    <property name="targetMethod"><value>getHostName</value></property>
</bean>
Run Code Online (Sandbox Code Playgroud)

此时,我在'host'bean中有主机名.我现在需要连接它并将它传递给publishedEndpointUrl属性.像这样的东西:

<jaxws:endpoint 
    id="foo"
    publishedEndpointUrl= "http://" + host + "/Foo" 
    implementor="com.example.v1.foo"
    address="/v1/Foo"/>
Run Code Online (Sandbox Code Playgroud)

如何使用spring xml配置完成?

ben*_*y23 18

你可以使用Spring-ELfactory-method:

<bean id="localhost" class="java.net.InetAddress" factory-method="getLocalHost" />

<bean id="publishedUrl" class="java.lang.String">
    <constructor-arg value="#{'http://' + localhost.hostName + '/Foo'}" />
</bean>

<jaxws:endpoint
   ...
   publishedEndpointUrl="#publishedUrl"
   ...
Run Code Online (Sandbox Code Playgroud)

编辑:

jaxws:endpoint标签似乎是能够通过使用引用豆值#beanId格式,但不喜欢春天-EL.因此,通过构建一个Stringbean,我们可以解决这个问题,它仍然看起来相当整洁.