Spring Boot Websockets in Wildfly

匿名 (未验证) 提交于 2019-12-03 01:49:02

问题:

Hi I need to deploy my Spring Boot app into Wildfly 8.1 and I'm getting the following exception:

Caused by: java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:219) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87) at org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72) at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] ... 3 more Caused by: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer cannot be cast to io.undertow.websockets.jsr.ServerWebSocketContainer at io.undertow.websockets.jsr.Bootstrap$WebSocketListener.contextInitialized(Bootstrap.java:69) at io.undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:190) ... 7 more

It seems that my setup for websockets and messaging might be the culprit? I was looking at this https://github.com/joshlong/boot-examples/issues/2 And none of the proposed solutions seem to work for me. Here are the dependencies from my pom:

org.springframework.bootspring-boot-starter-parent1.1.6.RELEASEjunitjunit4.11testorg.springframework.bootspring-boot-starter-testtestorg.apache.httpcomponentshttpclient${apache.httpcomponents.version}org.springframework.bootspring-boot-starter-weborg.springframework.bootspring-boot-starter-tomcatprovidedorg.springframework.bootspring-boot-starter-actuatororg.springframework.bootspring-boot-starter-data-jpaorg.springframeworkspring-websocketorg.springframeworkspring-messagingorg.thymeleafthymeleaf-spring4com.fasterxml.jackson.corejackson-databindorg.hsqldbhsqldb2.3.1postgresqlpostgresql9.1-901.jdbc4

I tried using the direct spring-boot-starter-websocket as well but get the same thing. Here is my websocket config too:

@Configuration @EnableWebSocketMessageBroker public class WebSocketConfig extends AbstractWebSocketMessageBrokerConfigurer{  @Override public void configureMessageBroker(MessageBrokerRegistry registry) {     super.configureMessageBroker(registry);     registry.enableSimpleBroker("/ssp");     registry.setApplicationDestinationPrefixes("/inc"); }  @Override public void registerStompEndpoints(StompEndpointRegistry registry) {     registry.addEndpoint("/update/applications"); } } 

Thanks for taking the time to read this. Any help would me most appreciated. Also, this is my first boot application. :/

回答1:

You need exclude tomcat-embed-websocket

org.springframework.bootspring-boot-starter-weborg.apache.tomcat.embedtomcat-embed-websocket


回答2:

spring-boot-starter-web and spring-boot-starter-websocket by default includes the spring-boot-starter-tomcat so exclude the tomcat, like below

     org.springframework.bootspring-boot-starter-web${spring-boot.version}org.springframework.bootspring-boot-starter-tomcatorg.springframework.bootspring-boot-starter-websocket${spring-boot.version}org.springframework.bootspring-boot-starter-tomcat

and include undertow, make sure the tomcat exists no where in the classpath.



回答3:

I'm not sure, but your POM around websockets should be like this:

org.springframework.bootspring-boot-starter-websocketorg.apache.tomcat.embedtomcat-embed-websocketprovidedorg.springframework.bootspring-boot-starter-tomcatprovided

spring-messaging, spring-websocket, jackson-databind, spring-boot-starter-web are redundant.

There is also spring-boot-starter-thymeleaf.

However I think the root of your cause is tomcat-embed-websocket.



回答4:

Use the following command to find all dependencies that includes spring-boot-starter-tomcat:

mvn dependency:tree -Dincludes=org.springframework.boot:spring-boot-starter-tomcat 

Exclude Tomcat starter from all your dependencies listed by this command.

After that, you might need to add javax.servlet-api as a provided dependency:

javax.servletjavax.servlet-apiprovided

Gradle users with this issue: check out the comments on this ticket: https://github.com/spring-projects/spring-boot/issues/6166



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!