Java 码头关闭

Java 码头关闭,java,spring,spring-boot,jetty,Java,Spring,Spring Boot,Jetty,几天前,我突然发现Jetty graceful shutdown没有自动与SpringBoot一起工作,Jetty服务器在Spring上下文已经关闭后停止,所以我的应用程序中出现了很多错误。因此,我必须在ContextClosedEvent上编写@EventListener来处理关闭服务和停止JettyEmbeddedServletContainer的命令 @Configuration public class MyContextConfiguration { @Autowired

几天前,我突然发现Jetty graceful shutdown没有自动与SpringBoot一起工作,Jetty服务器在Spring上下文已经关闭后停止,所以我的应用程序中出现了很多错误。因此,我必须在
ContextClosedEvent
上编写
@EventListener
来处理关闭服务和停止
JettyEmbeddedServletContainer
的命令

@Configuration
public class MyContextConfiguration {

    @Autowired
    private EmbeddedWebApplicationContext webApplicationContext;

    @EventListener(ContextClosedEvent.class)
    public void shutdown() {   
        webApplicationContext.getEmbeddedServletContainer().stop();

        myService1.stop();
        myService2.stop();
    }
}
有了这段代码,Jetty服务器将首先停止,因此无法创建任何新连接,并且可以处理已收到的请求。但在这种情况下,Jetty不会为一些最后收到的请求发送2xx响应,即使这些请求已成功处理。我得到了一个错误:

org.eclipse.jetty.server.HttpChannel     : /some/api/example

org.eclipse.jetty.io.EofException: null
    at org.eclipse.jetty.server.HttpConnection$SendCallback.reset(HttpConnection.java:677) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpConnection$SendCallback.access$300(HttpConnection.java:641) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpConnection.send(HttpConnection.java:521) [jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpChannel.sendResponse(HttpChannel.java:730) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpChannel.write(HttpChannel.java:786) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:234) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpOutput.write(HttpOutput.java:218) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at org.eclipse.jetty.server.HttpOutput.flush(HttpOutput.java:392) ~[jetty-server-9.4.7.v20170914.jar:9.4.7.v20170914]
    at com.fasterxml.jackson.core.json.UTF8JsonGenerator.flush(UTF8JsonGenerator.java:1054) ~[jackson-core-2.8.10.jar:2.8.10]
    at com.fasterxml.jackson.databind.ObjectWriter.writeValue(ObjectWriter.java:953) ~[jackson-databind-2.8.10.jar:2.8.10] 

有人能帮我吗

什么是myService1.stop()?错误发生在哪一行?@MartinMeeser,myService1.stop()执行一些操作以小心地停止服务,服务实际上向数据库发送请求。Jetty停止时出错,它处理请求队列(在QueuedThreadPool中),但即使请求处理成功(实体保存到DB),也会向客户端发送5xx响应。引发的异常附在上面