我有一个运行在tomcat 7.0.47上的spring4 websocket应用程序,可以,但是部署到weblogic 12.2.1.3.0时出现以下错误,
GET /bos/springws/echo HTTP/1.1<br/>
Connection: Upgrade<br/>
Pragma: no-cache<br/>
Cache-Control: no-cache<br/>
Upgrade: websocket<br/>
Origin: http://10.10.20.106:7001<br/>
Sec-WebSocket-Version: 13<br/>
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100 Safari/537.36<br/>
Accept-Encoding: gzip, deflate<br/>
Accept-Language: en,zh-CN;q=0.8,zh;q=0.6<br/>
Sec-WebSocket-Key: aGQU/agd8J0kE7yMlWS/4Q==<br/>
Sec-WebSocket-Extensions: permessage-deflate; client_max_window_bits<br/>
<br/>
]] Root cause of ServletException.<br/>
org.springframework.web.socket.server.HandshakeFailureException: Uncaught failure for request http://10.10.20.106:7001/bos/springws/echo; nested exception is java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?<br/>
at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:174)<br/>
at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:51)<br/>
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)<br/>
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)<br/>
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)<br/>
Truncated. see log file for complete stacktrace<br/>
Caused By: java.lang.IllegalArgumentException: No 'javax.websocket.server.ServerContainer' ServletContext attribute. Are you running in a Servlet container that supports JSR-356?<br/>
at org.springframework.util.Assert.notNull(Assert.java:115)<br/>
at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getContainer(AbstractStandardUpgradeStrategy.java:68)<br/>
at org.springframework.web.socket.server.standard.AbstractStandardUpgradeStrategy.getSupportedExtensions(AbstractStandardUpgradeStrategy.java:88)<br/>
at org.springframework.web.socket.server.support.AbstractHandshakeHandler.doHandshake(AbstractHandshakeHandler.java:272)<br/>
at org.springframework.web.socket.server.support.WebSocketHttpRequestHandler.handleRequest(WebSocketHttpRequestHandler.java:166)<br/>
Truncated. see log file for complete stacktrace<br/>
我检查了文档“ https://docs.spring.io/spring/docs/current/spring-framework-reference/web.html#websocket-server-deployment”,发现可能是“ SpringServletContainerInitializer”不起作用,因此在weblogic.xml中添加一些配置
<?xml version="1.0" encoding="ISO-8859-1"?>
<weblogic-web-app xmlns="http://xmlns.oracle.com/weblogic/weblogic-web-app">
<context-root>/bos</context-root>
<container-descriptor>
<prefer-web-inf-classes>false</prefer-web-inf-classes>
<prefer-application-packages>
<package-name>antlr.*</package-name>
<package-name>org.slf4j.*</package-name>
<package-name>com.ctc.wstx.*</package-name>
<package-name>org.apache.velocity.*</package-name>
<package-name>com.google.common.*</package-name>
<package-name>org.joda.time.*</package-name>
<package-name>javax.annotation.*</package-name>
<!-- for spring websocket -->
<package-name>javax.websocket.*</package-name>
<package-name>javax.websocket.server.*</package-name>
</prefer-application-packages>
<prefer-application-resources>
<resource-name>org/slf4j/impl/StaticLoggerBinder.class</resource-name>
</prefer-application-resources>
</container-descriptor>
<session-descriptor>
<cookie-http-only>true</cookie-http-only>
</session-descriptor>
<jsp-descriptor>
<page-check-seconds>1</page-check-seconds>
</jsp-descriptor>
</weblogic-web-app>
它可以正常工作,但给我另一个错误,但仍然无法设置
[ERROR] 2018-08-15 16:38:24:891 org.springframework.web.context.ContextLoader (ContextLoader.java:351) - Context initialization failed
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'webSocketHandlerMapping' defined in class path resource
[org/springframework/web/socket/config/annotation/DelegatingWebSocketConfiguration.class]:
Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException:
Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'webSocketHandlerMapping' threw exception;
nested exception is java.lang.IllegalStateException: Failed to instantiate RequestUpgradeStrategy: org.springframework.web.socket.server.standard.WebLogicRequestUpgradeStrategy
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1173) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1067) ~[spring-beans-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at
......<br/>
Caused by: java.lang.ExceptionInInitializerError: null
at org.springframework.web.socket.server.standard.WebLogicRequestUpgradeStrategy.<clinit>(WebLogicRequestUpgradeStrategy.java:55) ~[spring-websocket-4.3.6.RELEASE.jar:4.3.6.RELEASE]<br/>
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) ~[na:1.8.0_162]
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) ~[na:1.8.0_162]<br/>
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) ~[na:1.8.0_162]<br/>
at java.lang.reflect.Constructor.newInstance(Constructor.java:423) ~[na:1.8.0_162]<br/>
at java.lang.Class.newInstance(Class.java:442) ~[na:1.8.0_162]
at org.springframework.web.socket.server.support.AbstractHandshakeHandler.initRequestUpgradeStrategy(AbstractHandshakeHandler.java:148) ~[spring-websocket-4.3.6.RELEASE.jar:4.3.6.RELEASE]<br/>
... 106 common frames omitted<br/>
Caused by: java.lang.IllegalStateException: No compatible Tyrus version found
at org.springframework.web.socket.server.standard.AbstractTyrusRequestUpgradeStrategy$Tyrus17EndpointHelper.<clinit>(AbstractTyrusRequestUpgradeStrategy.java:211) ~[spring-websocket-4.3.6.RELEASE.jar:4.3.6.RELEASE]<br/>
... 113 common frames omitted
Caused by: java.lang.IllegalStateException: No compatible Tyrus version found
at org.springframework.web.socket.server.standard.AbstractTyrusRequestUpgradeStrategy$Tyrus17EndpointHelper.getEndpointConstructor(AbstractTyrusRequestUpgradeStrategy.java:222) ~[spring-websocket-4.3.6.RELEASE.jar:4.3.6.RELEASE]
at org.springframework.web.socket.server.standard.AbstractTyrusRequestUpgradeStrategy$Tyrus17EndpointHelper.<clinit>(AbstractTyrusRequestUpgradeStrategy.java:200) ~[spring-websocket-4.3.6.RELEASE.jar:4.3.6.RELEASE]
这很奇怪,我加了
tyrus-server-1.11.jar
tyrus-spi-1.11.jar
tyrus-client-1.11.jar
到\ WEB-INF \ lib 却行不通。