我有一个与Why spring webflux is choosing jetty by default and then failing?中描述的gradle和spring webflux有点类似的配置。
但我们的目标是在内存中的netty (而不是jetty)上有Amazon memory db + spring webflux用于我们的单元测试(我们已经在netty上有了带有spring webfux的生产发电机db )。我可以使用内存中的发电机db运行单元测试,但是一旦我启用了springboot webflux,它就开始抱怨:
Caused by: java.lang.NoClassDefFoundError: org/eclipse/jetty/servlet/ServletHolder
at org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory.createJettyServer(JettyReactiveWebServerFactory.java:176) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.web.embedded.jetty.JettyReactiveWebServerFactory.getWebServer(JettyReactiveWebServerFactory.java:106) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.<init>(ReactiveWebServerApplicationContext.java:202) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext$ServerManager.get(ReactiveWebServerApplicationContext.java:221) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.createWebServer(ReactiveWebServerApplicationContext.java:90) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.onRefresh(ReactiveWebServerApplicationContext.java:79) ~[spring-boot-2.1.5.RELEASE.jar:2.1.5.RELEASE]
... 62 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.eclipse.jetty.servlet.ServletHolder我在我的build.gradle中尝试了如下操作:
configurations {
// exclude Reactor Jetty /Tomcat
compile.exclude group: 'org.springframework.boot',module: 'spring-boot-starter-jetty'
testcompile.exclude group: 'org.springframework.boot',module: 'spring-boot-starter-jetty'
//compile.exclude group: 'javax.servlet' , module: 'servlet-api' //<--tried servlet jar exclusion also
}
.....
testCompile ('com.amazonaws:DynamoDBLocal:1.11.477')
....//event tried this ( and is probably wrong)
testCompile("org.springframework.boot:spring-boot-starter-test:$springBootVersion") {
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-jetty' //by both name and group
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
}我检查了依赖图:
\--- com.amazonaws:DynamoDBLocal:1.11.477
+--- org.antlr:antlr4-runtime:4.7.2
+--- commons-cli:commons-cli:1.2
+--- org.apache.commons:commons-lang3:3.8.1
+--- com.almworks.sqlite4java:libsqlite4java-linux-i386:1.0.392
| \--- com.almworks.sqlite4java:sqlite4java:1.0.392
+--- com.almworks.sqlite4java:libsqlite4java-linux-amd64:1.0.392
| \--- com.almworks.sqlite4java:sqlite4java:1.0.392
+--- com.almworks.sqlite4java:sqlite4java-win32-x64:1.0.392
| \--- com.almworks.sqlite4java:sqlite4java:1.0.392
+--- com.almworks.sqlite4java:sqlite4java-win32-x86:1.0.392
| \--- com.almworks.sqlite4java:sqlite4java:1.0.392
+--- com.almworks.sqlite4java:libsqlite4java-osx:1.0.392
| \--- com.almworks.sqlite4java:sqlite4java:1.0.392
+--- com.amazonaws:aws-java-sdk-core:1.11.477 (*)
+--- com.amazonaws:aws-java-sdk-dynamodb:1.11.477 (*)
+--- org.apache.logging.log4j:log4j-api:2.6.2 -> 2.11.2
+--- org.apache.logging.log4j:log4j-core:2.6.2 -> 2.11.2
| \--- org.apache.logging.log4j:log4j-api:2.11.2
+--- org.eclipse.jetty:jetty-client:8.1.12.v20130726 -> 9.4.18.v20190429
| +--- org.eclipse.jetty:jetty-http:9.4.18.v20190429
| | +--- org.eclipse.jetty:jetty-util:9.4.18.v20190429
| | \--- org.eclipse.jetty:jetty-io:9.4.18.v20190429
| | \--- org.eclipse.jetty:jetty-util:9.4.18.v20190429
| \--- org.eclipse.jetty:jetty-io:9.4.18.v20190429 (*)
+--- org.eclipse.jetty:jetty-server:8.1.12.v20130726 -> 9.4.18.v20190429
| +--- javax.servlet:javax.servlet-api:3.1.0 -> 4.0.1
| +--- org.eclipse.jetty:jetty-http:9.4.18.v20190429 (*)
| \--- org.eclipse.jetty:jetty-io:9.4.18.v20190429 (*)
+--- org.mockito:mockito-core:1.10.19 -> 2.23.4
| +--- net.bytebuddy:byte-buddy:1.9.3 -> 1.9.12所以我需要的是强制webflux使用Netty作为服务器。我认为它正在被dynamodb依赖项或某些jar传递性所覆盖。
发布于 2019-07-12 01:54:23
我遇到了完全相同的问题。问题是DynamoDBLocal库传递地引用了Jetty。由于Jetty和Netty都在类路径中,Webflux认为它应该开始使用Jetty而不是Netty。我能够通过遵循Spring Boot文档中详细介绍的内容来解决这个问题:https://docs.spring.io/spring-boot/docs/current/reference/html/howto-embedded-web-servers.html#howto-configure-webserver
特别是这一部分:
作为最后的手段,您还可以声明自己的WebServerFactory组件,它将覆盖Spring Boot提供的组件。
更具体地说,您可以将此代码添加到您的测试配置中(或者,如果您希望明确告诉所有内容始终使用Netty,则可以添加到您的整个应用程序配置中):
@Bean
public ReactiveWebServerFactory reactiveWebServerFactory() {
return new NettyReactiveWebServerFactory();
}发布于 2020-08-26 21:05:02
这里也有同样的问题。我怀疑某些内部条件迫使Tomcat而不是Netty,但我无法理解。
我结合了这三个变化解决了这个问题:
由于Evan Lennick!)
application.properties,
org.springframework.boot:spring-boot-starter-reactory-netty dependecyNettyReactiveWebServerFactory bean我希望这能有所帮助!
发布于 2020-07-10 21:42:05
此问题已在Spring Boot 2.2.9版本中解决:
https://stackoverflow.com/questions/56783116
复制相似问题