Grails 2.x service injection in Groovy/src

后端 未结 4 1115
醉酒成梦
醉酒成梦 2020-12-16 17:10

I\'d like to inject my service in Groovy/src class. The normaln dependency injection doesn\'t work:

...
def myService
...

I\'m able to use

4条回答
  •  抹茶落季
    2020-12-16 17:46

    The replacement of ApplicationHolder can be Holders, you can also use it in static scope:

    import grails.util.Holders
    ...
    
    def myService = Holders.grailsApplication.mainContext.getBean 'myService'
    

提交回复
热议问题