我可以在本地主机上访问WebUtils.retrieveGrailsWebRequest()
(一切正常)。但是,如果我尝试在tomcat服务器上部署.war文件,则会出现以下错误:
Caused by: java.lang.IllegalStateException: No thread-bound request found: Are you referring to request attributes outside of an actual web request, or processing a request outside of the originally receiving thread? If you are actually operating within a web request and still receive this message, your code is probably running outside of DispatcherServlet/DispatcherPortlet: In this case, use RequestContextListener or RequestContextFilter to expose the current request.
at org.springframework.web.context.request.RequestContextHolder.currentRequestAttributes(RequestContextHolder.java:131)
at org.grails.web.util.WebUtils.retrieveGrailsWebRequest(WebUtils.java:442)
at org.grails.web.util.WebUtils$retrieveGrailsWebRequest.call(Unknown Source)
at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:47)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:120)
at pos.kasse.session.SessionService.getCurrentUser(SessionService.groovy:25)
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.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:98)
at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
at org.codehaus.groovy.runtime.metaclass.MethodMetaProperty$GetBeanMethodMetaProperty.getProperty(MethodMetaProperty.java:76)
at org.codehaus.groovy.runtime.callsite.GetEffectivePogoPropertySite.getProperty(GetEffectivePogoPropertySite.java:85)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:299)
答案 0 :(得分:0)
您可以访问request
和/或session
,而无需引用任何所有者或引用WebUtils
。
// grails-app/services/lastone/DemoService.groovy
package lastone
import grails.web.api.ServletAttributes
class DemoService implements ServletAttributes {
def someMethod() {
// From here you can access the
// session and/or request properties
// directly...
}
}
答案 1 :(得分:-1)
问题是springsecurity插件。您必须从那里使用请求/会话:
import grails.plugin.springsecurity.web.SecurityRequestHolder as SRH
SRH.request.session