我得到异常 - org.apache.catalina.core.ApplicationDispatcher.invoke抛出异常java.lang.IllegalStateException

时间:2018-05-08 07:11:19

标签: java spring tomcat spring-security

我的服务器日志中出现以下错误,

08-May-2018 12:00:07.460 SEVERE [https-jsse-nio-8443-exec-1] org.apache.catalina.core.ApplicationDispatcher.invoke Servlet.service() for servlet [jsp] threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response
    at org.apache.catalina.connector.Response.getWriter(Response.java:624)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at org.springframework.security.web.util.OnCommittedResponseWrapper.getWriter(OnCommittedResponseWrapper.java:149)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:111)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:176)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
    at org.apache.jsp.WEB_002dINF.views.uncaughtException_html._jspService(uncaughtException_html.java:209)


    08-May-2018 12:00:07.468 SEVERE [https-jsse-nio-8443-exec-1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [xyz] in context with path [] threw exception java.lang.IllegalStateException: getOutputStream() has already been called for this response] with root cause java.lang.IllegalStateException: getOutputStream() has already been called for this response     
    at org.apache.catalina.connector.Response.getWriter(Response.java:624)
    at org.apache.catalina.connector.ResponseFacade.getWriter(ResponseFacade.java:211)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at javax.servlet.ServletResponseWrapper.getWriter(ServletResponseWrapper.java:109)
    at org.springframework.security.web.util.OnCommittedResponseWrapper.getWriter(OnCommittedResponseWrapper.java:149)
    at org.apache.jasper.runtime.JspWriterImpl.initOut(JspWriterImpl.java:118)
    at org.apache.jasper.runtime.JspWriterImpl.flushBuffer(JspWriterImpl.java:111)
    at org.apache.jasper.runtime.PageContextImpl.release(PageContextImpl.java:176)
    at org.apache.jasper.runtime.JspFactoryImpl.internalReleasePageContext(JspFactoryImpl.java:120)
    at org.apache.jasper.runtime.JspFactoryImpl.releasePageContext(JspFactoryImpl.java:75)
    at org.apache.jsp.WEB_002dINF.views.uncaughtException_html._jspService(uncaughtException_html.java:209)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
    at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)

我不知道哪个方法会抛出此错误,导致此错误的原因是什么。实际上,当我在tomcat中部署我的应用程序并尝试获取索引页面时出现此异常(有时是第一次,有时是第二次,有时是第三次,无论什么时候它都会出现。),实际上根据我的配置时ssl已启用,当我部署我的应用程序并尝试获取欢迎页面会话过期页面被调用,从现在一旦我尝试获取其他一些页面,它会抛出上述异常。我正在使用弹簧4,弹簧安全,maven,冬眠4.任何人都可以帮助我吗?任何帮助都会得到满足。

的web.xml

<web-app>
    <display-name>Smart app Application</display-name>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/spring-security.xml, /WEB-INF/app-servlet.xml
        </param-value>
    </context-param>

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <listener>
        <listener-class>org.springframework.security.web.session.HttpSessionEventPublisher</listener-class>
    </listener>

    <servlet>
        <servlet-name>app</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>app</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <servlet-mapping>
        <servlet-name>jsp</servlet-name>
        <url-pattern>/WEB-INF/views/*</url-pattern>
    </servlet-mapping>

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>application</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>

    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <welcome-file-list>
        <welcome-file>index</welcome-file>
    </welcome-file-list>

    <session-config>
        <session-timeout>50</session-timeout>
    </session-config>
</web-app>

1 个答案:

答案 0 :(得分:0)

如果您有SimpleMappingExceptionResolver,请尝试检查您是否与ControllerAdvice注释类发生冲突。例外情况只能在一个地方处理。

正如我所说,它可能是由一个周期性的关系和Jackason作为序列化器产生的。在这里你有一些选项,比如使用简化答案的DTO或用户@JsonIgnore。