Springboot stomp WebSocket找不到jakarta,WebSocket

hs1ihplo  于 2023-04-28  发布在  Spring
关注(0)|答案(1)|浏览(418)

我正在使用Intellij和Gradle在Java中使用Springboot框架开发WebSocket stomp客户端和服务器的第一步。我成功地创建了一个工作示例。现在,我正在更改代码以使用java模块系统,但在启动服务器应用程序时出现以下异常

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stompWebSocketHandlerMapping' defined in class path resource [org/springframework/web/socket/config/annotation/DelegatingWebSocketMessageBrokerConfiguration.class]: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception with message: jakarta/websocket/Endpoint
    at spring.beans@6.0.4/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:657) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:645) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1324) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1161) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:561) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:521) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:326) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:234) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:324) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:961) ~[spring-beans-6.0.4.jar:na]
    at spring.context@6.0.4/org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:915) ~[spring-context-6.0.4.jar:na]
    at spring.context@6.0.4/org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:584) ~[spring-context-6.0.4.jar:na]
    at spring.boot@3.0.2/org.springframework.boot.SpringApplication.refresh(SpringApplication.java:730) ~[spring-boot-3.0.2.jar:na]
    at spring.boot@3.0.2/org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:432) ~[spring-boot-3.0.2.jar:na]
    at spring.boot@3.0.2/org.springframework.boot.SpringApplication.run(SpringApplication.java:308) ~[spring-boot-3.0.2.jar:na]
    at spring.boot@3.0.2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1302) ~[spring-boot-3.0.2.jar:na]
    at spring.boot@3.0.2/org.springframework.boot.SpringApplication.run(SpringApplication.java:1291) ~[spring-boot-3.0.2.jar:na]
    at com.chesolver.tl.wsserverdue/com.chesolver.tl.example1.server.MessagingStompWebsocketApplication.main(MessagingStompWebsocketApplication.java:10) ~[wsserver-plain.jar:na]
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception with message: jakarta/websocket/Endpoint
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.web.servlet.HandlerMapping]: Factory method 'stompWebSocketHandlerMapping' threw exception with message: jakarta/websocket/Endpoint

    at spring.beans@6.0.4/org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) ~[spring-beans-6.0.4.jar:na]
    at spring.beans@6.0.4/org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:653) ~[spring-beans-6.0.4.jar:na]
    ... 18 common frames omitted
Caused by: java.lang.NoClassDefFoundError: jakarta/websocket/Endpoint

所以原因是没有找到jakarta.websocket。可能这是一个依赖性问题,但我不确定原因,代码在模块化之前是工作的,我希望spring-boot-starter-websocket将把jakarta带入游戏。实际上,我也得到了客户端应用程序的类似例外。
这是我的buil.gradle

plugins {
    id 'java'
    id 'org.springframework.boot' version '3.0.2'
    id 'io.spring.dependency-management' version '1.1.0'
}

repositories {
    mavenCentral()
}

dependencies {
    implementation 'org.springframework.boot:spring-boot-starter-websocket:3.0.2'
    implementation 'org.webjars:webjars-locator-core'
    implementation 'org.webjars:sockjs-client:1.0.2'
    implementation 'org.webjars:stomp-websocket:2.3.3'
    implementation 'org.webjars:bootstrap:3.3.7'
    implementation 'org.webjars:jquery:3.1.1-1'

    testImplementation 'org.springframework.boot:spring-boot-starter-test'

    implementation project(':core')
}

谢谢,任何提示都很感激!

yiytaume

yiytaume1#

尝试添加依赖项

<dependency>
    <groupId>jakarta.platform</groupId>
    <artifactId>jakarta.jakartaee-api</artifactId>
    <version>10.0.0</version>
    <scope>provided</scope>
</dependency>

相关问题