项目框架springboot2.0我写了父类BaseController里面自动注入request和responsepublicclassBaseController{@AutowiredpublicHttpServletRequestrequest;@AutowiredpublicHttpServletResponseresponse;}IndexController都继承BaseControllerpublicclassIndexControllerextendsBaseController{@RequestMapping("/index")publicStringindex(Modelmodel){return"index";}@RequestMapping("login")publicStringlogin()throwsServletException,IOException{request.getRequestDispatcher("/admin/index").forward(request,response);returnnull;}index页面,没有任何数据操作,纯一个静态页面500TEST访问http://localhost:9090/admin/login出现如下错误,循环引用导致内存溢出java.lang.StackOverflowError:nullatorg.springframework.web.context.support.WebApplicationContextUtils.currentRequestAttributes(WebApplicationContextUtils.java:312)atorg.springframework.web.context.support.WebApplicationContextUtils.access$400(WebApplicationContextUtils.java:65)atorg.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:328)atorg.springframework.web.context.support.WebApplicationContextUtils$RequestObjectFactory.getObject(WebApplicationContextUtils.java:323)atorg.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:305)atcom.sun.proxy.$Proxy100.setAttribute(UnknownSource)atorg.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:304)atsun.reflect.GeneratedMethodAccessor95.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:305)atcom.sun.proxy.$Proxy100.setAttribute(UnknownSource)atorg.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:304)atsun.reflect.GeneratedMethodAccessor95.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:305)atcom.sun.proxy.$Proxy100.setAttribute(UnknownSource)atorg.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:304)atsun.reflect.GeneratedMethodAccessor95.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)atorg.springframework.beans.factory.support.AutowireUtils$ObjectFactoryDelegatingInvocationHandler.invoke(AutowireUtils.java:305)atcom.sun.proxy.$Proxy100.setAttribute(UnknownSource)atorg.apache.catalina.core.ApplicationHttpRequest.setAttribute(ApplicationHttpRequest.java:304)atsun.reflect.GeneratedMethodAccessor95.invoke(UnknownSource)atsun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)atjava.lang.reflect.Method.invoke(Method.java:498)1.注意看我的login就使用request转发到首页(注意,此时request和response是父类的BaseController)注意问题不是地址循环跳引发的问题3.使用方法注入request和response就不会有问题@RequestMapping("login")publicStringlogin(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{request.getRequestDispatcher("/admin/index").forward(request,response);returnnull;}有没有大佬解释一波。
2 回答
偶然的你
TA贡献1841条经验 获得超3个赞
你先试试接口,@RequestMapping("cc")@ResponseBodypublicObjectz(){Stringparameter=request.getParameter("zz");System.out.println(parameter);return"你好";}springboot2.0.6没有问题,先一步一步的排查,世界是科学的
添加回答
举报
0/150
提交
取消