2017-02-14 55 views
1

我有使用spring引導1.4.0.RELEASE和嵌入式tomcat版本是8.5.4構建的spring引導web應用程序。我看到「IllegalStateException由於getOoputStream()已經在我的日誌中偶爾會調用」exception「。我不知道到底什麼時候發生。Spring引導web應用程序拋出getOutputStream()已被調用此響應

使用jsp,tiles和mvc rest controller建立的spring boot webapp。其餘的控制器非常簡單,它不使用響應流。這裏是我的錯誤日誌,

Caused by: java.lang.IllegalStateException: getOutputStream() has already been called for this response 
    at org.apache.catalina.connector.Response.getWriter(Response.java:609) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:118) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:111) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:176) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329) ~[tomcat-embed-jasper-8.5.4.jar!/:8.5.4] 
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:186) ~[spring-security-web-3.2.3.RELEASE.jar!/:3.2.3.RELEASE] 
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160) ~[spring-security-web-3.2.3.RELEASE.jar!/:3.2.3.RELEASE] 
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:101) ~[spring-web-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:726) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationDispatcher.doInclude(ApplicationDispatcher.java:592) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.catalina.core.ApplicationDispatcher.include(ApplicationDispatcher.java:526) ~[tomcat-embed-core-8.5.4.jar!/:8.5.4] 
    at org.apache.tiles.request.servlet.ServletRequest.doInclude(ServletRequest.java:243) ~[tiles-request-servlet-1.0.0.jar!/:1.0.0] 
    at org.apache.tiles.request.servlet.ServletRequest.doForward(ServletRequest.java:226) ~[tiles-request-servlet-1.0.0.jar!/:1.0.0] 
    at org.apache.tiles.request.AbstractClientRequest.dispatch(AbstractClientRequest.java:57) ~[tiles-request-api-1.0.0.jar!/:1.0.0] 
    at org.apache.tiles.request.render.DispatchRenderer.render(DispatchRenderer.java:45) ~[tiles-request-api-1.0.0.jar!/:1.0.0] 
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:259) ~[tiles-core-3.0.0.jar!/:3.0.0] 
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:397) ~[tiles-core-3.0.0.jar!/:3.0.0] 
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:238) ~[tiles-core-3.0.0.jar!/:3.0.0] 
    at org.apache.tiles.impl.BasicTilesContainer.render(BasicTilesContainer.java:221) ~[tiles-core-3.0.0.jar!/:3.0.0] 
    at org.apache.tiles.renderer.DefinitionRenderer.render(DefinitionRenderer.java:59) ~[tiles-core-3.0.0.jar!/:3.0.0] 
    at org.springframework.web.servlet.view.tiles3.TilesView.renderMergedOutputModel(TilesView.java:132) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.view.AbstractView.render(AbstractView.java:303) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.render(DispatcherServlet.java:1257) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.processDispatchResult(DispatcherServlet.java:1037) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:980) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970) ~[spring-webmvc-4.3.2.RELEASE.jar!/:4.3.2.RELEASE] 
    ... 25 more 








    @Controller 
    @RequestMapping("/") 
    public class MainController{   
     @RequestMapping(value = {"/list"}, method = RequestMethod.GET) 
     public String blacklist(ModelMap model) { 
      //processing 
      return "list"; 
     } 

     @RequestMapping(value = {"/Find"}, method = RequestMethod.POST) 
     public String find(ModelMap model, @ModelAttribute("attribute1")String attr) { 
      //processing 
      return "list"; 
     } 
    } 

回答

1

大多數情況下,這個錯誤與響應提交後調用任何servlet方法有關。檢查你的servlet代碼,看看在response.forward或response.flush方法之後是否有任何代碼行被寫入。響應寫入後它甚至可以是System.out。

+1

我沒有servlet在我的項目中,它都是彈簧控制器。代碼中沒有sys。還有什麼我應該看看? – skumar

0

如果您使用同時使用它的攔截器,請檢查它。也許攔截器使用響應 - outputStream。

0

如果你正在返回的bean /對象,沒有setter或getters,或者無法反映,你會得到這個錯誤。

相關問題