gpt4 book ai didi

tomcat - 在 Tomcat 中获取 WebUtils.retrieveGrailsWebRequest()

转载 作者:行者123 更新时间:2023-11-28 23:54:52 25 4
gpt4 key购买 nike

我可以在本地主机上访问 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)

最佳答案

您可以在不引用任何持有者或引用 WebUtils 的情况下访问 request 和/或 session

// 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...
}
}

关于tomcat - 在 Tomcat 中获取 WebUtils.retrieveGrailsWebRequest(),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56037422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com