Search code examples
grails

Grails : How do you make services available inside services?


I am currently running into an issue where I am attempting to use a service within a service however the service is null

class ApplicationService{
    def someService

    def someMethod(){
        someService.method()//null on someService
    }
}

Is there additional wiring that I need to perform for this to work? Thanks in advance for your help.


Solution

  • I was able to do this by using the grailsApplication and loading the service.

    if(!someService){
        someService = grailsApplication.classLoader.loadClass("org.company.SomeService").newInstance()
    }