Spring Boot WildFly 14:无法将类org.apache.tomcat.WebSocket.server.wsServerContainer强制转换为类io.undertow.websockets.jsr.服务器网络套接字容器

soat7uwm  于 2023-03-18  发布在  Spring
关注(0)|答案(2)|浏览(250)

尝试将Sping Boot 应用程序部署到WildFly 14时,我收到以下错误:
{“WFLYCTL0080:失败的服务”=〉{“jboss.deployment.unit.\“应用程序名称".undertow-deployment”=〉“java.lang运行时异常:java.lang.ClassCastException:无法将类org.apache.tomcat.WebSocket.server.wsServerContainer强制转换为类io.undertow. websocket.jsr.服务器网络套接字容器(org.apache.tomcat.websocket.server.wsServerContainer位于加载程序“部署.应用程序名称.war”的未命名模块中@56a6a8b7;服务器网络套接字容器位于加载程序“io.undertow.websocket@2.0.13.Final”@59ba0563的未命名模块中)原因如下:java.lang.RuntimeException:java.lang.ClassCastException:无法将类org.apache.tomcat.WebSocket.server.wsServerContainer强制转换为类io.undertow. websocket.jsr.服务器网络套接字容器(org.apache.tomcat.websocket.server.wsServerContainer位于加载程序“部署.应用程序名称.war”的未命名模块中@56a6a8b7;服务器网络套接字容器位于加载程序“io.undertow.websocket@2.0.13.Final”@59ba0563的未命名模块中)原因如下:java.lang.ClassCastException:无法将类org.apache.tomcat.WebSocket.server.wsServerContainer强制转换为类io.undertow. websocket.jsr.服务器网络套接字容器(org.apache.tomcat.websocket.server.wsServerContainer位于加载程序“部署.应用程序名称.war”的未命名模块中@56a6a8b7;服务器网络套接字容器位于加载程序“io.undertow.websocket@2.0.13.Final”的未命名模块中@59ba0563)"}}
我已经尝试了我能在stackoverflow或其他博客,论坛等找到的一切,但没有运气。我最终得到了下面的pom.xml。

<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.foo.application_name</groupId>
<artifactId>application_name</artifactId>
<version>xxx</version>

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

<dependencies>
    <dependency>
        <groupId>org.glassfish.jaxb</groupId>
        <artifactId>jaxb-runtime</artifactId>
        <version>2.3.0.1</version>
    </dependency>
    <dependency>
        <groupId>javax.activation</groupId>
        <artifactId>activation</artifactId>
        <version>1.1.1</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <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>
           <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-undertow</artifactId>
    </dependency>
    <dependency>
        <groupId>org.apache.maven</groupId>
        <artifactId>maven-model</artifactId>
        <version>3.5.4</version>
    </dependency>
    <dependency>
        <groupId>org.modelmapper</groupId>
        <artifactId>modelmapper</artifactId>
        <version>2.2.0</version>
    </dependency>
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-validation</artifactId>
        <exclusions>
            <exclusion>
                <artifactId>tomcat-embed-el</artifactId>
                <groupId>org.apache.tomcat.embed</groupId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <dependency>
        <groupId>org.projectlombok</groupId>
        <artifactId>lombok</artifactId>
        <optional>true</optional>
    </dependency>
    <dependency>
        <!-- update Hibernate dependency on Javassist to 3.23.1 for Java 11 compatibility -->
        <groupId>org.javassist</groupId>
        <artifactId>javassist</artifactId>
        <version>3.23.1-GA</version>
    </dependency>
    <dependency>
        <!-- update Mockito dependency for Java 11 compatibility -->
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
        <version>2.22.0</version><!--$NO-MVN-MAN-VER$ -->
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>8.0.12</version><!--$NO-MVN-MAN-VER$ -->
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <scope>provided</scope>
    </dependency>
</dependencies>

<packaging>war</packaging>

<build>
    <defaultGoal>install</defaultGoal>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <executable>true</executable>
                <skipTests>true</skipTests>
            </configuration>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>

<repositories>
    <repository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-releases</id>
        <url>https://repo.spring.io/libs-release</url>
    </pluginRepository>
</pluginRepositories>

有人能检查一下我的pom.xml,告诉我遗漏了什么吗?

cu6pst1q

cu6pst1q1#

你必须使你的spring-boot-starter-underow为scope = provided。这对任何其他的web服务器都有效。

nuypyhwy

nuypyhwy2#

如果你要部署到外部servlet容器或应用服务器,他们应该排除内置容器(如果你只将其部署为war)或将其标记为provided(如果你希望war也是可执行的),这在文档中有描述(http://docs.spring.io/spring-boot/docs/1.3.5.RELEASE/reference/htmlsingle/# howto-create-a-deployable-war-file)。
您显示的项目有一个错误。您正在尝试使用Undertow,但您没有从spring-boot-starter-jersey中排除Tomcat。如果您正在JBoss上部署,他们还应该将spring-boot-starter-undertow依赖项标记为已提供或也将其排除。

相关问题