compile "org.grails:grails-spring:1.3.7"
Here is a snippet of the Spring XML I was trying to convert:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:property-placeholder location="classpath:config.properties"/>
<bean id="connectionFactory" class="org.springframework.jms.connection.CachingConnectionFactory">
<property name="targetConnectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="${jms.brokerUrl}"/>
</bean>
</property>
<property name="sessionCacheSize" value="10"/>
<property name="cacheProducers" value="false"/>
</bean>
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory"><ref local="connectionFactory"/></property>
</bean>
...
</beans>
All was okay until I tried to deal with the 'property-placeholder' for the config.properties. I tried lots of stuff and on a whim tried this very counterintuitive thing with a Java String for the property key that looks like a Groovy String that in the BeanBuilder should be interpolated:
beans {
xmlns context:"http://www.springframework.org/schema/context"
context.'property-placeholder'('location':'classpath:config.properties')
activeMqConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) {
brokerURL = '${jms.brokerUrl}' // Yes, this is meant to be a java.lang.String
}
jmsFactory(org.springframework.jms.connection.CachingConnectionFactory) {
targetConnectionFactory = activeMqConnectionFactory
}
jmsTemplate(org.springframework.jms.core.JmsTemplate) {
connectionFactory = jmsFactory
}
...
}
Yes boys and girls...
'${jms.brokerUrl}'
Major brain eff here with something that looks like it should be "${jms.brokerUrl}" with double quotes for Groovy String interpolation or perhaps even simply jms.brokerUrl like a variable attached to a dynamically generated property on the beans object. I even tried context['jms.brokerUrl']and beans['jms.brokerUrl']to no avail.
I tried the actual solution when it occurred to me that Spring would not be doing interpolation on the ${blah} like Groovy when reading the XML. For Spring, that means 'use this string as a key to a resource'.
Oyvay.
No comments:
Post a Comment