I have a working websocket configured and running on Spring Web MVC 5.3.23 with Jetty 9.4.48. When I attempt to upgrade to Jetty 10.0.12, the server responds with 500 Server Error when clients try to open a websocket connection due to the following exception:
org.springframework.web.socket.server.HandshakeFailureException: Failed to upgrade; nested exception is java.lang.IllegalArgumentException: org.eclipse.jetty.websocket.server.JettyWebSocketCreator referenced from a method is not visible from class loader
at org.springframework.web.socket.server.jetty.Jetty10RequestUpgradeStrategy.upgrade(Jetty10RequestUpgradeStrategy.java:124)
at org.springframework.web.socket.server.support.AbstractHandshakeHandler.doHandshake(AbstractHandshakeHandler.java:297)
at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:178)
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:52)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1071)
…
at org.eclipse.jetty.io.ssl.SslConnection$1.run(SslConnection.java:132)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:933)
at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:1077)
at java.base/java.lang.Thread.run(Thread.java:833)
Caused by: java.lang.IllegalArgumentException: org.eclipse.jetty.websocket.server.JettyWebSocketCreator referenced from a method is not visible from class loader
at java.base/java.lang.reflect.Proxy$ProxyBuilder.ensureVisible(Proxy.java:883)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.validateProxyInterfaces(Proxy.java:721)
at java.base/java.lang.reflect.Proxy$ProxyBuilder.(Proxy.java:648)
at java.base/java.lang.reflect.Proxy.lambda$getProxyConstructor$1(Proxy.java:440)
at java.base/jdk.internal.loader.AbstractClassLoaderValue$Memoizer.get(AbstractClassLoaderValue.java:329)
at java.base/jdk.internal.loader.AbstractClassLoaderValue.computeIfAbsent(AbstractClassLoaderValue.java:205)
at java.base/java.lang.reflect.Proxy.getProxyConstructor(Proxy.java:438)
at java.base/java.lang.reflect.Proxy.newProxyInstance(Proxy.java:1037)
at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:126)
at org.springframework.aop.framework.JdkDynamicAopProxy.getProxy(JdkDynamicAopProxy.java:118)
at org.springframework.aop.framework.ProxyFactory.getProxy(ProxyFactory.java:97)
at org.springframework.web.socket.server.jetty.Jetty10RequestUpgradeStrategy.createJettyWebSocketCreator(Jetty10RequestUpgradeStrategy.java:134)
at org.springframework.web.socket.server.jetty.Jetty10RequestUpgradeStrategy.upgrade(Jetty10RequestUpgradeStrategy.java:116)
... 116 more
The IllegalArgumentException
originates in java.lang.reflect.Proxy.ensureVisible
, which is attempting to ensure that the org.eclipse.jetty.webapp.WebAppClassLoader
can see/load the JettyWebSocketCreator
class. Note that JettyWebSocketCreator
has already been successfully loaded by the main class loader. For some reason though, the WebAppClassLoader
can't find it.
How can I prevent this exception?