Search code examples
springgrailsgroovyproxyjavabeans

Using Spring DSL in a Grails Plugin


I'm trying to use the Spring DSL functionality in a Grails plugin. However, it doesn't work. Here's what I have in my plugin's conf/spring/resources.groovy file:

import org.springframework.aop.scope.ScopedProxyFactoryBean

// Place your Spring DSL code here
beans = {
  baseSvcProxy(ScopedProxyFactoryBean) {
    targetBeanName = 'baseService'
    proxyTargetClass = true
  }
}

However, it seems to be completely ignored. If I move the exact same code to the application's conf/spring/resources.groovy file everything works perfectly. Is there something that needs to be done differently for plugins for this to work?


Solution

  • In order to modify the spring context from a Grails plugin you need to use the doWithSpring section of your plugin by hooking into the runtime configuration. Resources.groovy is ignored in plugins.