grailsgrails-3.3grails-services

Grails 3 : ServletContext is coming null in grails service


I am unable to get servletcontext while calling 1 service method from another.

And if i move that called code to calling service class then its working fine.

CreditFilesService CreditFilesService

LakshyaUtilsService LakshyaUtilsService Code

java.lang.NullPointerException: Cannot get property 'configuration' on null object at org.codehaus.groovy.runtime.NullObject.getProperty(NullObject.java:60) at org.codehaus.groovy.runtime.InvokerHelper.getProperty(InvokerHelper.java:174) at org.codehaus.groovy.runtime.callsite.NullCallSite.getProperty(NullCallSite.java:47) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:296) at com.lakshya.LakshyaUtilsService.uploadFilesToAWS(LakshyaUtilsService.groovy:3074) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.springsource.loaded.ri.ReflectiveInterceptor.jlrMethodInvoke(ReflectiveInterceptor.java:1427) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:210) at org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.call(PogoMetaMethodSite.java:71) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.lakshya.credit.CreditFilesService.generateZipFile(CreditFilesService.groovy:110) at com.lakshya.credit.CreditFilesService$generateZipFile.call(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:141)


Solution

  • This was caused due to issue in code

    Grails 2 was able to call private method from one service to another service with all internal injections being done properly.

    While in Grails 3.3.3/3.3.4 it was calling the private method but the injections was not happening. so this issue was coming.