I have code scattered through a Service in a plugin, using AntBuilder like this:
def ant = new AntBuilder()
This results in code that is really hard to test I'd like to inject a prototype-scoped AntBuilder that I can replace with a mock. But, I'm pretty much a Spring newbie ... how would I do that?
I tried simply putting this in /grails-app/conf/spring/resources.groovy:
beans = {
antBuilderBean(groovy.util.AntBuilder){b ->
b.scope="prototype"
}
}
and
class MyService {
def antBuilderBean
but antBuilderBean is null. If I put the bean definition in the application's resources.groovy (rather than the plugin's resources.groovy), then the bean name shows up in the application context, but antBuilderBean still resoves to null in the service code.
Do I need some sort of a factory bean here? Or, do I have to explicitly build the bean from the Spring context or something?