猿问

非常诡异的内存溢出,希望有大佬教育一波

项目框架springboot2.0我写了父类BaseController里面自动注入request和response
publicclassBaseController{
@Autowired
publicHttpServletRequestrequest;
@Autowired
publicHttpServletResponseresponse;
}
IndexController都继承BaseController
publicclassIndexControllerextendsBaseController{
@RequestMapping("/index")
publicStringindex(Modelmodel){
return"index";
}
@RequestMapping("login")
publicStringlogin()throwsServletException,IOException{
request.getRequestDispatcher("/admin/index").forward(request,response);
returnnull;
}
index页面,没有任何数据操作,纯一个静态页面
500

TEST

访问http://localhost:9090/admin/login出现如下错误,循环引用导致内存溢出java.lang.StackOverflowError:null
atorg.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;
}
有没有大佬解释一波。
FFIVE
浏览 918回答 2
2回答

偶然的你

你先试试接口,@RequestMapping("cc")@ResponseBodypublicObjectz(){Stringparameter=request.getParameter("zz");System.out.println(parameter);return"你好";}springboot2.0.6没有问题,先一步一步的排查,世界是科学的
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答