Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在spring mvc中使用服务器发送事件时出现异常_Java_Spring_Spring Mvc_Server Sent Events - Fatal编程技术网

Java 在spring mvc中使用服务器发送事件时出现异常

Java 在spring mvc中使用服务器发送事件时出现异常,java,spring,spring-mvc,server-sent-events,Java,Spring,Spring Mvc,Server Sent Events,我是春天的新手。我想在我的项目中使用服务器发送的事件,但在测试SSE发射器时,我在服务器日志中得到了此异常 SEVERE: Servlet.service() for servlet dispatcher threw exception java.lang.UnsupportedOperationException: No async support in a pre-Servlet 3.0 runtime at org.springframework.web.context.request.a

我是春天的新手。我想在我的项目中使用服务器发送的事件,但在测试SSE发射器时,我在服务器日志中得到了此异常

SEVERE: Servlet.service() for servlet dispatcher threw exception
java.lang.UnsupportedOperationException: No async support in a pre-Servlet 3.0 runtime
at org.springframework.web.context.request.async.NoSupportAsyncWebRequest.startAsync(NoSupportAsyncWebRequest.java:62)
at org.springframework.web.context.request.async.WebAsyncManager.startAsyncProcessing(WebAsyncManager.java:428)
at org.springframework.web.context.request.async.WebAsyncManager.startDeferredResultProcessing(WebAsyncManager.java:408)
at org.springframework.web.servlet.mvc.method.annotation.ResponseBodyEmitterReturnValueHandler.handleReturnValue(ResponseBodyEmitterReturnValueHandler.java:159)
at org.springframework.web.method.support.HandlerMethodReturnValueHandlerComposite.handleReturnValue(HandlerMethodReturnValueHandlerComposite.java:81)
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:130)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:861)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:317)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:127)
at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:91)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:115)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:137)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:111)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:169)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:63)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.www.BasicAuthenticationFilter.doFilterInternal(BasicAuthenticationFilter.java:158)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.ui.DefaultLoginPageGeneratingFilter.doFilter(DefaultLoginPageGeneratingFilter.java:177)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:200)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:121)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:66)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:105)
at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:331)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:214)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
at org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:876)
at org.apache.coyote.http11.Http11AprProtocol$Http11ConnectionHandler.process(Http11AprProtocol.java:612)
at org.apache.tomcat.util.net.AprEndpoint$Worker.run(AprEndpoint.java:1777)
at java.lang.Thread.run(Thread.java:745)
用于测试Sse的控制器代码:

SseTest.jsp


试验
if(window.EventSource)
{
var source=neweventsource('/Sse/getEmitter');
source.onmessage=函数(e){
控制台日志(如数据);
};
source.onopen=函数(e){
console.log('Connected');
};
source.onerror=函数(e){
if(e.readyState==EventSource.CLOSED){
console.log(“连接关闭”);
}
};
}
其他的
{
log('EventSource不受支持');
}
在浏览器控制台中,我获得了连接,但没有收到任何消息。发送消息时,我在服务器日志中收到异常

My web.xml:


上下文配置位置
类路径:spring-security.xml
org.springframework.web.context.ContextLoaderListener
调度员
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
类路径:dispatcher-servlet.xml
1.
调度员
/
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
My pom.xml:


4.0.0
ru试验
扫雷舰
1.0-快照
战争
4.3.3.1发布
4.1.3.1发布
4.3.9.最终版本
1.9.13
org.springframework
弹簧芯
${spring.version}
org.springframework
SpringWebMVC
${spring.version}
org.springframework.security
spring安全配置
${spring.security.version}
org.springframework.security
spring安全网
${spring.security.version}
org.springframework
德克萨斯州春季
${spring.version}
org.springframework
春季甲虫
${spring.version}
org.hibernate
hibernate-c3p0
${hibernate.version}
org.hibernate
冬眠核心
${hibernate.version}
公共dbcp
公共dbcp
1.4
postgresql
postgresql
9.1-901-1.jdbc4
com.fasterxml.jackson.core
杰克逊核心
2.6.3
com.fasterxml.jackson.core
杰克逊数据绑定
2.6.3
com.fasterxml.jackson.core
杰克逊注释
2.6.3
javax.servlet
servlet api
2.5
假如
jstl
jstl
1.2
运行时
公用记录
公用记录
1.1.3
塔格利布
标准
1.1.2
公地郎
公地郎
2.1
org.codehaus.plexus
尾丛
1.1
朱尼特
朱尼特
4.8.2
测试
org.mockito
莫基托所有
1.10.19
测试
com.efsavage.jquery
jQueryMaven
1.7.2
org.apache.maven.plugins
maven战争插件
src/main/webapp/WEB-INF/WEB.xml
org.apache.maven.plugins
maven编译器插件
1.8
1.8

这是因为servel mus具有
true
这是因为您在不支持Servlet API v3及更高版本的容器中运行应用程序。Tomcat6只支持ServletAPI v2.5


您需要在更现代的servlet容器中运行它。Tomcat 7或更高版本就可以了。

您是否在容器中运行此代码?(例如Tomcat)。如果是,您运行的是哪个版本?@DaveH-Tomcat 6.0.47试图将其添加到web.xml的servlet标记中,但没有帮助尝试添加以下代码@WebFilter(urlPatterns=“/*”,asyncSupported=true),谢谢。其中一个问题是,我不得不将true添加到filter中,但出现异常的主要原因是tomcatYou's wellcome的旧版本
package ru.test.Controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;

@Controller
@RequestMapping("/SseTest")
public class SseTestController {
private static SseEmitter emitter;

@RequestMapping("/Page")
public String testPage(){
    return "SseTest";
}

@RequestMapping("/getEmitter")
public SseEmitter getEmitter(){
    emitter = new SseEmitter();
    try {
        emitter.send("testmessage");
    } catch (IOException e) {
        e.printStackTrace();
    }
    return emitter;
}

@RequestMapping(value = "/sendMessage/{message}", method = RequestMethod.GET)
public ModelAndView sendMessage(@PathVariable String message){
    ModelAndView modelAndView = new ModelAndView("SseMessage");
    try {
        emitter.send(message);
        modelAndView.addObject("Status",true);
        modelAndView.addObject("Message",message);
    } catch (IOException e) {
        modelAndView.addObject("Status",false);
        modelAndView.addObject("Message",e.toString());
        e.printStackTrace();
    }
    return modelAndView;
}

@RequestMapping(value = "/complete", method = RequestMethod.GET)
public ModelAndView complete(){
    ModelAndView modelAndView = new ModelAndView("SseMessage");
    emitter.complete();
    modelAndView.addObject("Status",true);
    modelAndView.addObject("Message","complete");
    return modelAndView;
}
}
<html>
<head>
    <title>Test</title>
</head>
<body>


<script>
    if(window.EventSource)
    {
        var source = new EventSource('/Sse/getEmitter');

        source.onmessage = function(e) {
            console.log(e.data);
        };

        source.onopen = function(e) {
            console.log('Connected');
        };

        source.onerror = function(e) {
            if (e.readyState == EventSource.CLOSED) {
                console.log('Connection closed');
            }
        };
    }
    else
    {
        console.log('EventSource is not supported');
    }
</script>
</body>
</html>