Set up string reference in proxy.xml

26 views
Skip to first unread message

victo...@gmail.com

unread,
Mar 30, 2015, 10:53:40 AM3/30/15
to membrane...@googlegroups.com
Hi, when configure the proxy.xml for multiple rules sometimes we have requirements to share the same resource string in different tags. Instead of duplicate the setup, is it possible to define a string at one place then reference it multiple times elsewhere? e.g.

<string id="string1" value="abc.net" />
<string id="port1" value="1234" />

<target host="${string1}" port ="${port1}">

Tobias Polley

unread,
Mar 30, 2015, 11:06:19 AM3/30/15
to membrane...@googlegroups.com, victo...@gmail.com
Hi Victor,

probably using Spring's PropertyPlaceholderConfigurer works.

http://docs.spring.io/spring/docs/3.1.2.RELEASE/spring-framework-reference/htmlsingle/spring-framework-reference.html#beans-factory-placeholderconfigurer

In your example it would be

<spring:beans ...>
  <spring:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <spring:property name="properties">
      <spring:value>string1=abc.net</spring:value>
    </spring:property>
  </spring:bean>

<router>
<serviceProxy ...>
...
<target host="${string1}"/>
</serviceProxy>
</router>
</spring:beans>

Please let us know whether it does!

Best, Tobias

victo...@gmail.com

unread,
Mar 31, 2015, 12:12:26 PM3/31/15
to membrane...@googlegroups.com, victo...@gmail.com
Great, but it somehow only works for the <target> host property, if I apply it to the port property it just failed with following error:

12:08:25,762 ERROR HotDeploymentThread:90 - line 123: cvc-datatype-valid.1.2.1: '$p{string1}' is not a valid value for 'integer'.

and here is my config:
<spring:beans ...>
  <spring:property name="placeholderPrefix" value="$p{" />
  <spring:property name="placeholderSuffix" value="}" />
  <spring:bean class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
    <spring:property name="properties">
      <spring:value>string1=5679</spring:value>
    </spring:property>
  </spring:bean>

<router>
<serviceProxy ...>
...
<target port="$p{string1}" host="abc.net"/>
</serviceProxy>
</router>
</spring:beans>
Reply all
Reply to author
Forward
0 new messages