Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I list the available objects to inject in grails?

Is there a way to programatically list all available beans in the grails spring injection context? In guice I was able to do this by looking up the bindings configured in the injector.

like image 963
benstpierre Avatar asked Apr 16 '13 19:04

benstpierre


1 Answers

I use this:

ctx.beanDefinitionNames.sort().each { println it }

where ctx is the Spring ApplicationContext. You can get that in a controller/service/etc. with

def grailsApplication
...
def ctx = grailsApplication.mainContext

Given all of the bean names, you can inspect individual ones with

def bean = ctx.getBean(name)
like image 63
Burt Beckwith Avatar answered Oct 24 '22 16:10

Burt Beckwith