Arthur Neves
Arthur Neves

Reputation: 12128

grails plugin dynamic bean creation

I am trying to register a bean in my plugin, but the 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

Upvotes: 1

Views: 787

Answers (1)

Burt Beckwith
Burt Beckwith

Reputation: 75671

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.

Upvotes: 2

Related Questions