I was having issues trying to get my Spring DSL to operate in ./grails-app/spring/resources.groovy. I have been able to use XML formatting in resources.xml, but I wanted to leverage groovy as well as be able to replace certain beans based on environment such as using Mock objects during test.
There are several issues I had in my conversion.
First: I needed to use equal signs (=) instead of colon (:) for assignments. I see the colon notation everywhere, and even in some Spring examples, but it did not work for me.
So this: serviceName : “RoutingLookupService”
changed into: serviceName = “RoutingLookupService”
Second: I had another issue trying to get my external configuration from ${userHome}/.grails/${appName}-config.groovy into this bean declaration.
So this: wsdlDocumentUrl = “${routingLookupService.wsdlDocumentUrl}
changed into: wsdlDocumentUrl = ConfigurationHolder.config.routingLookupService.wsdlDocumentUrl
In the end, I has ended up with the following declaration for resources.groovy
import org.codehaus.groovy.grails.commons.ConfigurationHolder
beans = {
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
switch (grails.util.GrailsUtil.environment) {
case "production":
println "Creating production Spring beans"
routingLookupService(org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean) {
serviceInterface = "com.comcast.ivr.das.services.RoutingLookupServicePortType"
wsdlDocumentUrl = ConfigurationHolder.config.routingLookupService.wsdlDocumentUrl
namespaceUri = "http://services.das.ivr.comcast.com"
serviceName = "RoutingLookupService"
endpointAddress = ConfigurationHolder.config.routingLookupService.endpointAddress
maintainSession = "true"
}
break
case "test":
println "Creating test Spring beans"
routingLookupService(org.easymock.EasyMock,
"com.comcast.ivr.das.services.RoutingLookupServicePortType") {bean ->
bean.factoryMethod = "createMock"
}
break
case "development":
println "Creating development Spring beans"
routingLookupService(org.springframework.remoting.jaxws.JaxWsPortProxyFactoryBean) {
serviceInterface = "com.comcast.ivr.das.services.RoutingLookupServicePortType"
wsdlDocumentUrl = ConfigurationHolder.config.routingLookupService.wsdlDocumentUrl
namespaceUri = "http://services.das.ivr.comcast.com"
serviceName = "RoutingLookupService"
endpointAddress = ConfigurationHolder.config.routingLookupService.endpointAddress
maintainSession = "true"
}
break
} // switch
routingLookupServiceClient(com.comcast.ivr.das.domain.routinglookup.xsd.RoutingLookupServiceClient)
println "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
} // End beans.

