gpt4 book ai didi

java - Cometd、Jetty : Cometd wont start, 抽象错误 :javax. servlet.ServletOutputStream.setWriteListener

转载 作者:行者123 更新时间:2023-12-02 12:11:49 26 4
gpt4 key购买 nike

我正在尝试在 Jetty 9.2 上运行我们的 Spring-MVC 应用程序,该应用程序具有 Cometd(3.0.9)。目前它与 Tomcat7 完美配合,但我们正在将 Jetty 作为另一个应用程序容器来满足其他一些要求。但是,Cometd 不会启动,并抛出 500。这是我们在后端一次又一次遇到的唯一错误:

2017-09-29 12:48:17.137:WARN:oejs.HttpInput:qtp717356484-66: java.lang.AbstractMethodError: javax.servlet.ServletOutputStream.setWriteListener(Ljavax/servlet/WriteListener;)V

web.xml:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>cometd</servlet-name>
<servlet-class>org.cometd.server.CometDServlet</servlet-class>
<init-param>
<param-name>maxSessionsPerBrowser</param-name>
<param-value>10</param-value>
</init-param>
<init-param>
<param-name>allowMultiSessionsNoBrowser</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>timeout</param-name>
<param-value>60000</param-value>
</init-param>
<init-param>
<param-name>long-polling.jsonp.timeout</param-name>
<param-value>30000</param-value>
</init-param>
<init-param>
<param-name>long-polling.timeout</param-name>
<param-value>40000</param-value>
</init-param>
<init-param>
<param-name>interval</param-name>
<param-value>0</param-value>
</init-param>
<init-param>
<param-name>maxInterval</param-name>
<param-value>300000</param-value>
</init-param>
<init-param>
<param-name>long-polling.multiSessionInterval</param-name>
<param-value>2000</param-value>
</init-param>
<init-param>
<param-name>multiFrameInterval</param-name>
<param-value>1000</param-value>
</init-param>
<init-param>
<param-name>logLevel</param-name>
<param-value>3</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>
</servlet>


<servlet-mapping>
<servlet-name>cometd</servlet-name>
<url-pattern>/cometd/*</url-pattern>
</servlet-mapping>


<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<async-supported>true</async-supported>

</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>

控制台错误:

POST /cometd/handshake HTTP/1.1
Host: localhost:8080
Connection: keep-alive
Content-Length: 201
Accept: */*
Origin: http://localhost:8080
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Ubuntu Chromium/61.0.3163.79 Chrome/61.0.3163.79 Safari/537.36
Content-Type: application/json;charset=UTF-8
DNT: 1
Referer: http://localhost:8080/canvaslisting
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.8,en;q=0.6
Cookie: BAYEUX_BROWSER=1ul0bye0whhe511o; language=de; express_sid=s%3APCZq7dlCE8SlD6Iz86erUOv9tzSY3ByZ.4I%2BjSqnjONlhbuZOW90xM%2BeVjDnGQv0h0faztPBGan8; token=t.acvNouIKHegdIIFTjUjV; io=UiTHlpSm-T0vFYL1AAAA; JSESSIONID=1xktmtvfdgw5qtfqsf4et10g; _gat=1; sessionID=s.0dd75393a703ba234388cc605b84b790%2Cs.6fd7622c942a1808476c55355c46c8e4%2Cs.0dd75393a703ba234388cc605b84b790%2Cs.6fd7622c942a1808476c55355c46c8e4; _ga=GA1.1.1967903258.1505904823; _gid=GA1.1.1406412351.1506495950

HTTP/1.1 500 Server Error
Access-Control-Allow-Origin: http://localhost:8080
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers:
Content-Type: application/json;charset=UTF-8
Content-Length: 0
Server: Jetty(9.2.22.v20170606)

Cometd 依赖项:

<!-- Cometd dependencies -->
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>bayeux-api</artifactId>
<version>${cometd-version}</version>
</dependency>
<dependency>
<groupId>org.cometd.javascript</groupId>
<artifactId>cometd-javascript-jquery</artifactId>
<version>${cometd-version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-server</artifactId>
<version>${cometd-version}</version>
</dependency>

<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>9.2.9.v20150224</version>
</dependency>

<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-client</artifactId>
<version>${cometd-version}</version>
</dependency>

<dependency>
<groupId>org.cometd.java</groupId>
<artifactId>cometd-java-annotations</artifactId>
<version>${cometd-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.jetty/jetty-servlets -->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-servlets</artifactId>
</dependency>

Bayeux初始化器:

@Component
public class BayeuxInitializer implements DestructionAwareBeanPostProcessor, ServletContextAware {
private BayeuxServer bayeuxServer;
private ServerAnnotationProcessor processor;

@Inject
private void setBayeuxServer(BayeuxServer bayeuxServer) {
this.bayeuxServer = bayeuxServer;
}

@PostConstruct
private void init(){

this.processor = new ServerAnnotationProcessor(bayeuxServer);
}

@PreDestroy
private void destroy() {
}

public Object postProcessBeforeInitialization(Object bean, String name) throws BeansException {
processor.processDependencies(bean);
processor.processConfigurations(bean);
processor.processCallbacks(bean);

return bean;
}

public Object postProcessAfterInitialization(Object bean, String name) throws BeansException {
return bean;
}

public void postProcessBeforeDestruction(Object bean, String name) throws BeansException {
processor.deprocessCallbacks(bean);
}

@Bean(initMethod = "start", destroyMethod = "stop")
public BayeuxServer bayeuxServer() {

return new BayeuxServerImpl();
}

public void setServletContext(ServletContext servletContext) {
servletContext.setAttribute(BayeuxServer.ATTRIBUTE, bayeuxServer);
}
}



@Listener(value = "/service/online")
public void OnlineNotifications(ServerSession remote, ServerMessage.Mutable message) {
Person person = this.personService.getCurrentlyAuthenticatedUser();

// This person is always null in Jetty, but not on Apache tomcat.
}

最佳答案

您的 web.xml 声明 Web 应用程序为 Servlet 3.1。

ServletOutputStream.setWriteListener(WriteListener)是Servlet 3.1中添加的方法。

您收到的错误:

java.lang.AbstractMethodError: javax.servlet.ServletOutputStream.setWriteListener(Ljavax/servlet/WriteListener;)V

表示您已针对 Servlet 3.1 jar 编译了应用程序,但您在不提供此类 jar 的环境中运行它,可能只是 Servlet 3.0 jar。

Jetty 9.2.x 开箱即用,支持 Servlet 3.1。

我怀疑您有一个错误的类路径,您在其中引用了导致该错误的旧 jar ,因此我会首先仔细检查。

如果您要在独立的 Jetty 9.2.x 服务器中部署 Web 应用程序,请确保 Web 应用程序的 WEB-INF/lib 中的 jar 包正确。

关于java - Cometd、Jetty : Cometd wont start, 抽象错误 :javax. servlet.ServletOutputStream.setWriteListener,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46483804/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com