开发者

grails plugin dynamic bean creation

开发者 https://www.devze.com 2023-03-18 08:43 出处:网络
I am trying to register a bean in my plugin, but t开发者_如何学运维he class(implementation) of that bean is configurable.

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

精彩评论

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

关注公众号