开发者

grails plugin dynamic bean creation

I am trying to register a bean in my plugin, but t开发者_如何学运维he class(implementation) of that bean is configurable.

in my TestGrailsPlugin.groovy file:

def doWithSpring = {
    userListener("${ConfigurationHolder.config.userListenerClass}")
}

but this is not working! what should I do, I guess should be really easy task. but didnt find anywhere!

cheers


You can load the class dynamically with the GrailsApplication's classloader:

def doWithSpring = {
   def clazz = application.classLoader.loadClass(application.config.userListenerClass)
   userListener(clazz)
}

Also note that I'm using application.config instead of using the holder class - the holders are deprecated in 2.0 and will be removed in a future release.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜