28

嗨,我需要将 Spring Boot 应用程序部署到 Wildfly 8.1 中,但出现以下异常:

原因:java.lang.RuntimeException: java.lang.ClassCastException: org.apache.tomcat.websocket.server.WsServerContainer 无法在 io.undertow.servlet.core.DeploymentManagerImpl 强制转换为 io.undertow.websockets.jsr.ServerWebSocketContainer。在 org.wildfly.extension.undertow.deployment.UndertowDeploymentService.startContext(UndertowDeploymentService.java:87) 在 org.wildfly.extension.undertow.deployment.UndertowDeploymentService.start(UndertowDeploymentService.java:72) 部署(DeploymentManagerImpl.java:219)在 org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] 在 org.jboss.msc.service.ServiceControllerImpl $StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final] ... 3 更多原因:java.lang。ClassCastException:org.apache.tomcat.websocket.server.WsServerContainer 无法在 io.undertow.websockets.jsr.Bootstrap$WebSocketListener.contextInitialized(Bootstrap.java:69) 处转换​​为 io.undertow.websockets.jsr.ServerWebSocketContainer。 undertow.servlet.core.ApplicationListeners.contextInitialized(ApplicationListeners.java:173) at io.undertow.servlet.core.DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:190) ... 还有 7 个DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:190) ... 还有 7 个DeploymentManagerImpl.deploy(DeploymentManagerImpl.java:190) ... 还有 7 个

看来我的 websockets 和消息传递设置可能是罪魁祸首?我在看这个https://github.com/joshlong/boot-examples/issues/2并且提议的解决方案似乎都不适合我。以下是我的 pom 中的依赖项:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>1.1.6.RELEASE</version>
</parent>

<dependencies>

    <!--Testing-->
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.11</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>

    <dependency>
        <groupId>org.apache.httpcomponents</groupId>
        <artifactId>httpclient</artifactId>
        <version>${apache.httpcomponents.version}</version>
    </dependency>

    <!-- Spring -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-tomcat</artifactId>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-actuator</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-websocket</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-messaging</artifactId>
    </dependency>
    <dependency>
        <groupId>org.thymeleaf</groupId>
        <artifactId>thymeleaf-spring4</artifactId>
    </dependency>
    <dependency>
        <groupId>com.fasterxml.jackson.core</groupId>
        <artifactId>jackson-databind</artifactId>
    </dependency>

    <!--Database-->
    <dependency>
        <groupId>org.hsqldb</groupId>
        <artifactId>hsqldb</artifactId>
        <version>2.3.1</version>
    </dependency>
    <dependency>
        <groupId>postgresql</groupId>
        <artifactId>postgresql</artifactId>
        <version>9.1-901.jdbc4</version>
    </dependency>
</dependencies>

我也尝试使用直接的 spring-boot-starter-websocket,但得到了同样的结果。这也是我的 websocket 配置:

@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");
}
}

感谢您抽时间阅读。我将不胜感激任何帮助。此外,这是我的第一个启动应用程序。:/

4

6 回答 6

48

您需要排除 tomcat-embed-websocket

<dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
于 2015-03-25T03:11:18.043 回答
13

spring-boot-starter-web 和 spring-boot-starter-websocket 默认包含 spring-boot-starter-tomcat 所以排除 tomcat,如下所示

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
        <version>${spring-boot.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

     <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <version>${spring-boot.version}</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>

并包括undertow,确保tomcat在类路径中不存在。

于 2015-03-11T22:46:51.127 回答
4

我不确定,但是您围绕 websockets 的 POM 应该是这样的:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-websocket</artifactId>
</dependency>

<dependency>
    <groupId>org.apache.tomcat.embed</groupId>
    <artifactId>tomcat-embed-websocket</artifactId>
    <scope>provided</scope>
</dependency>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

spring-messaging, spring-websocket, jackson-databind,spring-boot-starter-web是多余的。

还有spring-boot-starter-thymeleaf.

但是,我认为您的原因的根源是tomcat-embed-websocket.

于 2014-09-11T17:16:59.317 回答
2

使用以下命令查找所有依赖项,其中包括spring-boot-starter-tomcat

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

从此命令列出的所有依赖项中排除 Tomcat 启动程序。

之后,您可能需要添加javax.servlet-api作为提供的依赖项:

<dependency>
    <artifactId>javax.servlet</artifactId>
    <groupId>javax.servlet-api</groupId>
    <scope>provided</scope>
</dependency>

有此问题的 Gradle 用户:查看此票的评论:https ://github.com/spring-projects/spring-boot/issues/6166

于 2017-06-13T07:59:04.183 回答
0

好吧,上面给出的解决方案都不适合我。

实际上是父版本中的版本造成了问题。

不工作:

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.3.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

在职的:

     <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.0</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>
于 2021-06-03T11:34:48.547 回答
0

对我来说,spring-boot-starter-websocket 和 spring-boot-starter-web 默认包含 spring-boot-starter-tomcat 所以排除 tomcat,如下图没有 spring boot 版本:

<dependency>  
        <groupId>org.springframework.boot</groupId>  
        <artifactId>spring-boot-starter-web</artifactId>  
        <exclusions>
            <exclusion>
                <groupId>org.apache.tomcat.embed</groupId>
                <artifactId>tomcat-embed-websocket</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-websocket</artifactId>
        <exclusions>
            <exclusion>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-starter-tomcat</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
于 2020-11-23T09:14:17.130 回答