properties - Using Spring Expression Language to define xml attribute -
here problem: have read property (activemq.connector.port
) , add 2 , use set attribute (connectorport
) on bean managementcontext
. here property comes file or system property. spring not care suppose.
<amq:broker id="broker" usejmx="true" persistent="true"> <amq:managementcontext createconnector="true" connectorport="#{${activemq.connector.port}+2}"/> <amq:transportconnectors> <amq:transportconnector uri="vm://localhost:${activemq.connector.port:1099}"/> </amq:transportconnectors> </amq:broker>
when tried got exception.
caused by: org.springframework.beans.factory.nosuchbeandefinitionexception: no bean named '{1099 + 2 }' defined @ org.springframework.beans.factory.support.defaultlistablebeanfactory.getbeandefinition(defaultlistablebeanfactory.java:568) @ org.springframework.beans.factory.support.abstractbeanfactory.getmergedlocalbeandefinition(abstractbeanfactory.java:1108) @ org.springframework.beans.factory.support.abstractbeanfactory.dogetbean(abstractbeanfactory.java:278) @ org.springframework.beans.factory.support.abstractbeanfactory.getbean(abstractbeanfactory.java:194) @ org.springframework.beans.factory.support.beandefinitionvalueresolver.resolvereference(beandefinitionvalueresolver.java:323)
how make work? there alternative approaches achieve this?
before try: "#{2 + ${activemq.connector .port}}" force spel use placeholder numbers.
else use syntax (is spel notation java code integer.valueof(value of 'activemq.connector.port') + 2
):
#{ t(java.lang.integer).valueof('${activemq.connector.port}') + 2 }
probably ${} managed string , not number "cast" needed t(class).<staticmethod>(params)
spel syntax call static method
Comments
Post a Comment