sofastack / sofa-boot

SOFABoot is a framework that enhances Spring Boot and fully compatible with it, provides readiness check, class isolation, etc.
https://www.sofastack.tech/sofa-boot/docs/Home
Apache License 2.0
4.98k stars 1.27k forks source link

com.alipay.sofa.rpc.enable-swagger 是否已经废弃 在3.16.3 #1061

Closed LY1806620741 closed 1 year ago

LY1806620741 commented 1 year ago

Describe the bug

com.alipay.sofa.rpc.enable-swagger=true 配置使用了objectway的asm,与springboot的asm冲突。 另外,没有在sofaboot文档上找到所有的properties说明

To Reproduce

Steps to reproduce the behavior:

  1. 运行简单sofaboot
  2. 配置com.alipay.sofa.rpc.enable-swagger=true
  3. 启动并访问 http://localhost:8341/swagger/bolt/api
  4. debug可以看到 can't not found class objectway.classvisitor
  5. 引入asm.jar后会与sping框架的asm org.springframework.asm.ClassVisitor 冲突

Expected behavior

A clear and concise description of what you expected to happen.

Screenshots

If applicable, add screenshots to help explain your problem.

Environment:

Additional context

Add any other context about the problem here.

khotyn commented 1 year ago

@LY1806620741 SOFARPC 相关的配置在这里可以看到 https://www.sofastack.tech/projects/sofa-rpc/application-rpc-config/

khotyn commented 1 year ago

异常堆栈:

java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.alipay.sofa.rpc.filter.ProviderInvoker.invoke(ProviderInvoker.java:103)
    at com.alipay.sofa.rpc.filter.PressureMarkTransformFilter.invoke(PressureMarkTransformFilter.java:63)
    at com.alipay.sofa.rpc.filter.FilterInvoker.invoke(FilterInvoker.java:100)
    at com.alipay.sofa.rpc.filter.sofatracer.ProviderTracerFilter.invoke(ProviderTracerFilter.java:74)
    at com.alipay.sofa.rpc.filter.FilterInvoker.invoke(FilterInvoker.java:100)
    at com.alipay.sofa.rpc.filter.ProviderBaggageFilter.invoke(ProviderBaggageFilter.java:45)
    at com.alipay.sofa.rpc.filter.FilterInvoker.invoke(FilterInvoker.java:100)
    at com.alipay.sofa.rpc.filter.RpcServiceContextFilter.invoke(RpcServiceContextFilter.java:62)
    at com.alipay.sofa.rpc.filter.FilterInvoker.invoke(FilterInvoker.java:100)
    at com.alipay.sofa.rpc.filter.ProviderExceptionFilter.invoke(ProviderExceptionFilter.java:37)
    at com.alipay.sofa.rpc.filter.FilterInvoker.invoke(FilterInvoker.java:100)
    at com.alipay.sofa.rpc.filter.FilterChain.invoke(FilterChain.java:269)
    at com.alipay.sofa.rpc.server.ProviderProxyInvoker.invoke(ProviderProxyInvoker.java:68)
    at com.alipay.sofa.rpc.doc.swagger.rest.SwaggerRestService_proxy_0.api(SwaggerRestService_proxy_0.java)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:139)
    at org.jboss.resteasy.core.ResourceMethodInvoker.internalInvokeOnTarget(ResourceMethodInvoker.java:510)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTargetAfterFilter(ResourceMethodInvoker.java:400)
    at org.jboss.resteasy.core.ResourceMethodInvoker.lambda$invokeOnTarget$0(ResourceMethodInvoker.java:364)
    at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:355)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:366)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:338)
    at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:311)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:439)
    at com.alipay.sofa.rpc.server.rest.SofaSynchronousDispatcher.invoke(SofaSynchronousDispatcher.java:49)
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$invoke$4(SynchronousDispatcher.java:229)
    at org.jboss.resteasy.core.SynchronousDispatcher.lambda$preprocess$0(SynchronousDispatcher.java:135)
    at org.jboss.resteasy.core.interception.PreMatchContainerRequestContext.filter(PreMatchContainerRequestContext.java:355)
    at org.jboss.resteasy.core.SynchronousDispatcher.preprocess(SynchronousDispatcher.java:138)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:215)
    at org.jboss.resteasy.plugins.server.netty.RequestDispatcher.service(RequestDispatcher.java:83)
    at com.alipay.sofa.rpc.server.rest.SofaRestRequestHandler.channelRead0(SofaRestRequestHandler.java:103)
    at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:99)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:379)
    at io.netty.channel.AbstractChannelHandlerContext.access$600(AbstractChannelHandlerContext.java:61)
    at io.netty.channel.AbstractChannelHandlerContext$7.run(AbstractChannelHandlerContext.java:370)
    at io.netty.util.concurrent.AbstractEventExecutor.runTask$$$capture(AbstractEventExecutor.java:174)
    at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute$$$capture(AbstractEventExecutor.java:167)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:470)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:503)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at java.lang.Thread.run(Thread.java:750)
Caused by: java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
    at com.alipay.sofa.rpc.doc.swagger.generate.RpcReaderExtension.<init>(RpcReaderExtension.java:75)
    at com.alipay.sofa.rpc.doc.swagger.generate.Reader.read(Reader.java:126)
    at com.alipay.sofa.rpc.doc.swagger.generate.Reader.read(Reader.java:94)
    at com.alipay.sofa.rpc.doc.swagger.generate.GenerateService.generate(GenerateService.java:74)
    at com.alipay.sofa.rpc.doc.swagger.rest.SwaggerRestServiceImpl.api(SwaggerRestServiceImpl.java:38)
    ... 52 more
Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.ClassVisitor
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:419)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:352)
    ... 57 more
khotyn commented 1 year ago

@LY1806620741 可以手工增加一个

<dependency>
    <groupId>org.ow2.asm</groupId>
    <artifactId>asm</artifactId>
    <version>9.1</version>
</dependency>

的依赖。

看起来是 https://github.com/sofastack/sofa-rpc/blob/5.8.3.1/all/pom.xml 少添加了一个 asm 的依赖,导致出现上面的问题。

HzjNeverStop commented 1 year ago

最新的 4.0.0 版本已经修复了该问题,可以直接使用