alibaba / alibaba-rsocket-broker

Alibaba RSocket Broker: Mesh, Streaming & IoT
https://alibroker.info
Apache License 2.0
761 stars 167 forks source link

Java 17 启动报错 #211

Closed CoderYellow closed 2 years ago

CoderYellow commented 2 years ago

Describe the bug 之前说过srping 最新版支持 @RSocketExchange,我就想跑个demo试试,spring 6 最低支持Java 17 Java 17 运行报 Caused by: java.lang.NoSuchFieldError: MESSAGE_RSOCKET_APPLICATION

Environment

Steps to reproduce this issue

run the demo

Expected Result

What do you expected from the above steps?

Actual Result

What actually happens?

If there is an exception, please attach the exception trace:

Caused by: java.lang.NoSuchFieldError: MESSAGE_RSOCKET_APPLICATION
    at com.alibaba.rsocket.metadata.RSocketMimeType.<clinit>(RSocketMimeType.java:26) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.metadata.AppMetadata.getMimeType(AppMetadata.java:287) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.metadata.RSocketCompositeMetadata.addMetadata(RSocketCompositeMetadata.java:104) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.metadata.RSocketCompositeMetadata.from(RSocketCompositeMetadata.java:53) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.spring.boot.rsocket.RSocketRequesterSupportImpl.lambda$setupPayload$0(RSocketRequesterSupportImpl.java:78) ~[alibaba-rsocket-spring-boot-starter-1.1.3.jar:na]
    at com.alibaba.rsocket.loadbalance.LoadBalancedRSocket.connect(LoadBalancedRSocket.java:408) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.loadbalance.LoadBalancedRSocket.lambda$refreshRsockets$4(LoadBalancedRSocket.java:138) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at reactor.core.publisher.FluxFlatMap$FlatMapMain.onNext(FluxFlatMap.java:386) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxIterable$IterableSubscription.slowPath(FluxIterable.java:272) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxIterable$IterableSubscription.request(FluxIterable.java:230) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxFlatMap$FlatMapMain.onSubscribe(FluxFlatMap.java:371) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:165) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxIterable.subscribe(FluxIterable.java:87) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Mono.subscribe(Mono.java:4321) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Mono.subscribeWith(Mono.java:4387) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Mono.subscribe(Mono.java:4292) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Mono.subscribe(Mono.java:4228) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Mono.subscribe(Mono.java:4175) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at com.alibaba.rsocket.loadbalance.LoadBalancedRSocket.refreshRsockets(LoadBalancedRSocket.java:149) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at reactor.core.publisher.LambdaSubscriber.onNext(LambdaSubscriber.java:160) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxReplay$SizeBoundReplayBuffer.replayNormal(FluxReplay.java:877) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.FluxReplay$SizeBoundReplayBuffer.replay(FluxReplay.java:965) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.ReplayProcessor$ReplayInner.request(ReplayProcessor.java:615) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.LambdaSubscriber.onSubscribe(LambdaSubscriber.java:119) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.ReplayProcessor.subscribe(ReplayProcessor.java:329) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Flux.subscribe(Flux.java:8459) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Flux.subscribeWith(Flux.java:8580) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Flux.subscribe(Flux.java:8429) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Flux.subscribe(Flux.java:8353) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at reactor.core.publisher.Flux.subscribe(Flux.java:8296) ~[reactor-core-3.5.0-M4.jar:3.5.0-M4]
    at com.alibaba.rsocket.loadbalance.LoadBalancedRSocket.<init>(LoadBalancedRSocket.java:106) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.upstream.UpstreamCluster.init(UpstreamCluster.java:138) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.rsocket.upstream.UpstreamManagerImpl.init(UpstreamManagerImpl.java:119) ~[alibaba-rsocket-core-1.1.3.jar:na]
    at com.alibaba.spring.boot.rsocket.upstream.SmartLifecycleUpstreamManagerImpl.init(SmartLifecycleUpstreamManagerImpl.java:36) ~[alibaba-rsocket-spring-boot-starter-1.1.3.jar:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
    at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeCustomInitMethod(AbstractAutowireCapableBeanFactory.java:1852) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1809) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1749) ~[spring-beans-6.0.0-M5.jar:6.0.0-M5]
    ... 58 common frames omitted
CoderYellow commented 2 years ago

这地方好奇怪啊,用的版本明明有在这个属性,加载到虚拟机后又没有,会不会是Java 17兼容性问题,要不用Jdk 17 release一个版本试试 image

CoderYellow commented 2 years ago

原来是这个WellKnownMimeType被重定义了, 不知道为什么加载了rsocket-core原来的那个,没有加载这个

CoderYellow commented 2 years ago

这问题通过spring依赖的rsocket-core exclude掉可以解决,但不知道为什么要这样重定义来override,不可以声明一个自己包命名空间的枚举吗。 jvm在classpath上找到两个同名的class,好像不一定加载你重定义的那个。

linux-china commented 2 years ago

这个主要是由于RSocket Java中的WellKnownMimeType为enum类型,这个是没法被扩展的,所以只能做Class覆盖。事实上这个问题在企业内部开发也是经常需要的,https://github.com/rsocket/rsocket/blob/master/Extensions/WellKnownMimeTypes.md 上列出的已知类型无法覆盖到企业内部的一些特定类型需求,所以会存在class覆盖的问题。

考虑到Java类的加载机制,只要保证alibaba-rsocket-core依赖声明在先即可。 如果你公司也有不同的数据类型,也可以考虑同样的机制。 为何要选择这样的机制? 我使用content-type的字符串变量也是可以的,为何要添加到WellKnownMimeType中? 如果是字符串变量,会传输更多的字节,而在WellKnownMimeType中的类型,则是一个byte,如果每一个请求都要包括content-type的字符串值,这个会影响一定的性能。