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

1

12

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.

Bicknell answered 16/4, 2013 at 19:19 Comment(0)
W
24

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)
Wilburnwilburt answered 16/4, 2013 at 19:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.