gpt4 book ai didi

spring - 由于 Tomcat ServerContainer,Spring-Websocket 的 ClassCastException

转载 作者:行者123 更新时间:2023-11-28 21:53:07 26 4
gpt4 key购买 nike

尝试使用 SockJS 连接到 Spring Websocket 时出现错误

org.springframework.web.util.NestedServletException: Request processing failed; 
nested exception is org.springframework.web.socket.sockjs.SockJsException:
Uncaught failure in SockJS request, uri=http://localhost:8083//subscribe/info/771/nay07fet/websocket;
nested exception is org.springframework.web.socket.sockjs.SockJsTransportFailureException:
WebSocket handshake failure; nested exception is java.lang.ClassCastException:
org.eclipse.jetty.websocket.jsr356.server.ServerContainer cannot be cast
to org.apache.tomcat.websocket.server.WsServerContainer

从网上我想出我应该在Classpath中禁用Tomcat来克服它,但是无论我如何尝试,我都无法摆脱Tomcat。

我如何才能可靠地从任何项目中排除 tomcat?请注意,我在几个地方找到了它。

我当前的依赖树在这里:http://pastebin.com/pH1iQejd它包含一些 tomcat。 我需要摆脱所有可能导致这种类型混淆的东西。

这是我的 gradle.build(我尝试了一些 exlcudes 但没有成功):

group 'com.company'
if (!hasProperty("buildNumber")) {
version "1.0.0-SNAPSHOT"
} else {
version "1.0.${buildNumber}-SNAPSHOT"
}



buildscript {
repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}


}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:1.3.3.RELEASE")
classpath("gradle.plugin.com.boxfuse.client:flyway-release:4.0.1")
classpath fileTree(dir: 'libs', include: '*.jar')
classpath fileTree(dir: 'src/main/resources/db/migration', include: '*.sql')
}
}


apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'spring-boot'

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {
mavenCentral()
maven {
url "https://plugins.gradle.org/m2"
}

}


dependencies {
// tag::jetty[]
compile("org.springframework.boot:spring-boot-starter-web") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-jetty") {
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
// end::jetty[]
// tag::actuator[]
compile("org.springframework.boot:spring-boot-starter-actuator")
compile("org.springframework.boot:spring-boot-starter-data-jpa"){
exclude module: "spring-boot-starter-tomcat"
exclude module: 'spring-boot-starter-logging'
}
compile("org.springframework.boot:spring-boot-starter-data-rest")
compile("org.springframework.boot:spring-boot-starter-websocket")
// http://mvnrepository.com/artifact/org.springframework.security/spring-security-core
compile group: 'org.springframework.security', name: 'spring-security-core', version: '4.1.0.RELEASE'

compile group: 'ch.qos.logback', name: 'logback-classic', version: '1.+'
compile group: 'com.google.code.gson', name: 'gson', version: '2.5'
compile group: 'com.rabbitmq', name: 'amqp-client', version: '3.5.6'
compile group: 'commons-configuration', name: 'commons-configuration', version: '1.9'
compile group: 'com.google.guava', name: 'guava', version: '18.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.5'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.5'
compile("org.springframework:spring-messaging")
compile 'org.springframework.amqp:spring-rabbit:1.5.5.RELEASE'
compile("com.h2database:h2")
compile 'org.quartz-scheduler:quartz:2.2.1'
compile group: 'joda-time', name: 'joda-time', version: '2.3'
//compile("com.npspot:jtransit-light:1.0.6")
compile("io.fastjson:boon:0.33")
compile fileTree(dir: 'libs', include: '*.jar')
// end::actuator[]
testCompile group: 'junit', name: 'junit', version: '4.11'
testCompile("org.springframework.boot:spring-boot-starter-test")
}

configurations {
compile.exclude module: "spring-boot-starter-tomcat"
compile.exclude module: 'spring-boot-starter-logging'
runtime.exclude module: "spring-boot-starter-tomcat"
runtime.exclude module: 'spring-boot-starter-logging'
}

test {
reports {
junitXml.enabled = true
html.enabled = false
}
}

springBoot {
executable = true
}

最佳答案

我也遇到了这个问题。我通过将 exclude 子句添加到 websocket 依赖项来解决它,即:

compile("org.springframework.boot:spring-boot-starter-websocket") {
exclude module: "spring-boot-starter-tomcat"
}

在此之后,我意识到没有必要排除所有其他的;它仅在 starter-webstarter-websocket 上是必需的。

关于spring - 由于 Tomcat ServerContainer,Spring-Websocket 的 ClassCastException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37594715/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com