Pre-check
- [x] I am sure that all the content I provide is in English.
Search before asking
- [x] I had searched in the issues and found no similar issues.
Apache Dubbo Component
Java SDK (apache/dubbo)
Dubbo Version
dubbo 3.3.5,java 17,mac 15.6
Steps to reproduce this issue
在非 spring 环境,项目在 jvm 运行时下是正常的。。。使用 dubbo-native + dubbo-maven-plugin (原生编译时)出现以下异常。
- 异常
Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext
at java.base/java.lang.Class.getDeclaredConstructors0(Native Method)
at java.base/java.lang.Class.privateGetDeclaredConstructors(Class.java:3373)
at java.base/java.lang.Class.getConstructors(Class.java:2060)
at org.apache.dubbo.aot.generate.ReflectConfigMetadataRepository.buildTypeDescriberWithConstructor(ReflectConfigMetadataRepository.java:74)
at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
at org.apache.dubbo.aot.generate.ReflectConfigMetadataRepository.registerSpiExtensionType(ReflectConfigMetadataRepository.java:45)
at org.apache.dubbo.aot.generate.AotProcessor.main(AotProcessor.java:62)
Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:641)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
... 14 more
- 截图
What you expected to happen
希望 dubbo-native java 原生编译,不要硬性依赖 spring 相关接口。。。希望去除依赖,或者通过适配。。。希望在非 spring 环境下,也能使用。
Anything else
No response
Are you willing to submit a pull request to fix on your own?
- [ ] Yes I am willing to submit a pull request on my own!
Code of Conduct
- [x] I agree to follow this project's Code of Conduct
Comment From: zrlw
refer to https://cn.dubbo.apache.org/zh-cn/blog/2023/06/28/%E8%B5%B0%E5%90%91-native-%E5%8C%96springdubbo-aot-%E6%8A%80%E6%9C%AF%E7%A4%BA%E4%BE%8B%E4%B8%8E%E5%8E%9F%E7%90%86%E8%AE%B2%E8%A7%A3/
maybe the API mode meet your requirement. BTW, dubbo-samples-native-image
was moved to 2-advanced
.
Comment From: noear
@zrlw 你发的这个资料,用处不大。
开发时是在 “非 spring 环境”。jvm 模式下是正常的。。。但加个原生编译,就出错了。
内部依赖了 spring 的接口。。。希望(dubbo 原生编译)能在 “非 spring 环境” 运行!
Comment From: liucq200518
是的,同样的问题。不使用spring,单纯手动引入dubbo的场景下,直接运行是没有问题的,但是一旦执行native编译就会出现提示spring类缺失,我认为dubbo-native不应该强引用spring的相关类。或者换句话是,it should be a standalone component,for normal java project
Comment From: zrlw
pls rewrite your issue in english.
Comment From: zrlw
是的,同样的问题。不使用spring,单纯手动引入dubbo的场景下,直接运行是没有问题的,但是一旦执行native编译就会出现提示spring类缺失,我认为dubbo-native不应该强引用spring的相关类。或者换句话是,it should be a standalone component,for normal java project
could you provide a pr to fix it?
Comment From: zrlw
how to write Steps to reproduce this issue
1. provide your sample project which include the minimum codes and pom.xml that could reproduce your issue.
2. provide your mvn build script, such as mvn clean install -P native -Dmaven.test.skip=true
, make sure you use API mode to compile your project which does not depend on spring plugin.
Comment From: zrlw
是的,同样的问题。不使用spring,单纯手动引入dubbo的场景下,直接运行是没有问题的,但是一旦执行native编译就会出现提示spring类缺失,我认为dubbo-native不应该强引用spring的相关类。或者换句话是,it should be a standalone component,for normal java project
if you mean you take native:compile
in your build script such as mvn clean install -P native native:compile -Dmaven.test.skip=true
, it will use Springboot3
integration compile mode.
refer to https://cn.dubbo.apache.org/zh-cn/blog/2023/06/28/%E8%B5%B0%E5%90%91-native-%E5%8C%96springdubbo-aot-%E6%8A%80%E6%9C%AF%E7%A4%BA%E4%BE%8B%E4%B8%8E%E5%8E%9F%E7%90%86%E8%AE%B2%E8%A7%A3/
Comment From: noear
晚上,我提交一个能复现问题的示例项目。以及复现操作步骤
Comment From: noear
@zrlw
示例已准备好:
https://github.com/solonlab/solon-native-example/tree/dubbo
复现操作说明:
https://github.com/solonlab/solon-native-example/blob/dubbo/DUBBO.md
麻烦了
Comment From: zrlw
i could not determine the cause as you example project lacks of parent pom.
dubbo-native
does not depend on any spring components, but i found some components or plugins in pom.xml of solon-parent
(https://github.com/opensolon/solon/blob/main/solon-parent/pom.xml) actually depends on spring context, you'd better run mvn dependency:tree
and check those solon plugin codes to ensure that you project doesn't depend on spring indirectly.
Comment From: noear
那个包是通过 dependencyManagement 管理的,应该没有关系的吧。。。现在也已经移除了。
另外,示例项目运行 mvn dependency:tree
的效果(没有 spring 相关的依赖)
[INFO] Scanning for projects...
[INFO]
[INFO] ---------------< com.dudiao.solon:solon-native-example >----------------
[INFO] Building solon-native-example 1.0
[INFO] from pom.xml
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ solon-native-example ---
[INFO] com.dudiao.solon:solon-native-example:jar:1.0
[INFO] +- org.noear:solon-web:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-lib:jar:3.5.2-SNAPSHOT:compile
[INFO] | | +- org.noear:solon-mvc:jar:3.5.2-SNAPSHOT:compile
[INFO] | | +- org.noear:solon-cache:jar:3.5.2-SNAPSHOT:compile
[INFO] | | \- org.noear:solon-config-plus:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-server-smarthttp:jar:3.5.2-SNAPSHOT:compile
[INFO] | | +- org.noear:solon-server:jar:3.5.2-SNAPSHOT:compile
[INFO] | | +- org.noear:solon-net:jar:3.5.2-SNAPSHOT:compile
[INFO] | | +- org.noear:smart-http-server:jar:2.5.12:compile
[INFO] | | | \- org.noear:smart-http-common:jar:2.5.12:compile
[INFO] | | \- io.github.smartboot.socket:aio-pro:jar:1.5.55:compile
[INFO] | | \- io.github.smartboot.socket:aio-core:jar:1.5.55:compile
[INFO] | +- org.noear:solon-serialization-snack3:jar:3.5.2-SNAPSHOT:compile
[INFO] | | \- org.noear:solon-serialization:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-sessionstate-local:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-web-staticfiles:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-web-cors:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.noear:solon-security-validation:jar:3.5.2-SNAPSHOT:compile
[INFO] +- org.noear:solon-view-freemarker:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-view:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.freemarker:freemarker:jar:2.3.34:compile
[INFO] +- org.noear:solon-flow:jar:3.5.1:compile
[INFO] | +- org.noear:solon:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-config-yaml:jar:3.5.2-SNAPSHOT:compile
[INFO] | | \- org.yaml:snakeyaml:jar:2.4:compile
[INFO] | +- org.noear:snack3:jar:3.2.139:compile
[INFO] | +- org.slf4j:slf4j-api:jar:2.0.17:compile
[INFO] | +- org.noear:dami:jar:1.0.6:compile
[INFO] | \- org.noear:liquor-eval:jar:1.6.2:compile
[INFO] | \- org.noear:liquor:jar:1.6.2:compile
[INFO] +- org.noear:solon-logging-logback:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-logging:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- ch.qos.logback:logback-classic:jar:1.3.15:compile
[INFO] | | \- ch.qos.logback:logback-core:jar:1.3.15:compile
[INFO] | \- org.fusesource.jansi:jansi:jar:2.4.1:compile
[INFO] +- org.noear:solon-scheduling-quartz:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-scheduling:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.quartz-scheduler:quartz:jar:2.3.2:compile
[INFO] | +- com.mchange:c3p0:jar:0.9.5.4:compile
[INFO] | \- com.mchange:mchange-commons-java:jar:0.2.15:compile
[INFO] +- org.noear:nami-channel-http:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:nami:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.noear:solon-net-httputils:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.noear:solon-rx:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.reactivestreams:reactive-streams:jar:1.0.4:compile
[INFO] +- org.noear:nami-coder-snack3:jar:3.5.2-SNAPSHOT:compile
[INFO] +- org.noear:wood-solon-plugin:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:solon-data:jar:3.5.2-SNAPSHOT:compile
[INFO] | | \- org.noear:solon-security-vault:jar:3.5.2-SNAPSHOT:compile
[INFO] | +- org.noear:wood:jar:1.3.25:compile
[INFO] | \- org.noear:wood.plus:jar:1.3.25:compile
[INFO] +- com.baomidou:mybatis-plus-solon-plugin:jar:3.5.12:compile
[INFO] | +- com.baomidou:mybatis-plus-extension:jar:3.5.12:compile
[INFO] | | \- com.baomidou:mybatis-plus-core:jar:3.5.12:compile
[INFO] | | \- com.baomidou:mybatis-plus-annotation:jar:3.5.12:compile
[INFO] | \- org.noear:mybatis-solon-plugin:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.mybatis:mybatis:jar:3.5.17:compile
[INFO] +- com.baomidou:mybatis-plus-jsqlparser:jar:3.5.12:compile
[INFO] | +- com.github.jsqlparser:jsqlparser:jar:5.1:compile
[INFO] | \- com.baomidou:mybatis-plus-jsqlparser-common:jar:3.5.12:compile
[INFO] +- org.jetbrains.kotlin:kotlin-stdlib-jdk8:jar:2.1.0:provided
[INFO] | +- org.jetbrains.kotlin:kotlin-stdlib:jar:2.1.0:provided
[INFO] | | \- org.jetbrains:annotations:jar:13.0:provided
[INFO] | \- org.jetbrains.kotlin:kotlin-stdlib-jdk7:jar:2.1.0:provided
[INFO] +- org.jetbrains.kotlin:kotlin-reflect:jar:2.1.0:provided
[INFO] +- com.zaxxer:HikariCP:jar:4.0.3:compile
[INFO] +- com.h2database:h2:jar:2.2.224:compile
[INFO] +- org.noear:solon-aot:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- com.squareup:javapoet:jar:1.13.0:compile
[INFO] +- cn.hutool:hutool-core:jar:5.8.36:compile
[INFO] +- org.noear:dubbo3-solon-plugin:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.apache.dubbo:dubbo:jar:3.3.5:compile
[INFO] | +- org.javassist:javassist:jar:3.30.2-GA:compile
[INFO] | +- io.netty:netty-all:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-buffer:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-base:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-dns:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-haproxy:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-compression:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-http:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-http2:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-memcache:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-mqtt:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-redis:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-smtp:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-socks:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-stomp:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-xml:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-protobuf:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-marshalling:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-common:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-handler:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-native-unix-common:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-handler-proxy:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-handler-ssl-ocsp:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-resolver:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-rxtx:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-sctp:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-udt:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-classes-epoll:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-classes-kqueue:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-resolver-dns-classes-macos:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-classes-io_uring:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-codec-classes-quic:jar:4.2.1.Final:compile
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:linux-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:linux-aarch_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-epoll:jar:linux-riscv64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-io_uring:jar:linux-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-io_uring:jar:linux-aarch_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-io_uring:jar:linux-riscv64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-kqueue:jar:osx-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-transport-native-kqueue:jar:osx-aarch_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-resolver-dns-native-macos:jar:osx-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-resolver-dns-native-macos:jar:osx-aarch_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-codec-native-quic:jar:linux-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-codec-native-quic:jar:linux-aarch_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-codec-native-quic:jar:osx-x86_64:4.2.1.Final:runtime
[INFO] | | +- io.netty:netty-codec-native-quic:jar:osx-aarch_64:4.2.1.Final:runtime
[INFO] | | \- io.netty:netty-codec-native-quic:jar:windows-x86_64:4.2.1.Final:runtime
[INFO] | +- org.apache.dubbo:hessian-lite:jar:4.0.3:compile
[INFO] | +- com.alibaba.fastjson2:fastjson2:jar:2.0.56:compile
[INFO] | \- com.google.protobuf:protobuf-java:jar:3.25.7:compile
[INFO] +- org.apache.dubbo:dubbo-native:jar:3.3.5:compile
[INFO] | \- org.apache.dubbo:dubbo-common:jar:3.3.5:compile
[INFO] | +- commons-io:commons-io:jar:2.19.0:compile
[INFO] | \- javax.annotation:javax.annotation-api:jar:1.3.2:compile
[INFO] +- org.projectlombok:lombok:jar:1.18.38:provided
[INFO] \- org.noear:solon-test:jar:3.5.2-SNAPSHOT:test
[INFO] +- org.noear:solon-proxy:jar:3.5.2-SNAPSHOT:compile
[INFO] | \- org.ow2.asm:asm:jar:9.8:compile
[INFO] +- org.mockito:mockito-core:jar:4.11.0:test
[INFO] | +- net.bytebuddy:byte-buddy:jar:1.12.19:test
[INFO] | +- net.bytebuddy:byte-buddy-agent:jar:1.12.19:test
[INFO] | \- org.objenesis:objenesis:jar:3.3:test
[INFO] +- org.junit.jupiter:junit-jupiter:jar:5.11.4:test
[INFO] | +- org.junit.jupiter:junit-jupiter-api:jar:5.11.4:test
[INFO] | | +- org.opentest4j:opentest4j:jar:1.3.0:test
[INFO] | | +- org.junit.platform:junit-platform-commons:jar:1.11.4:test
[INFO] | | \- org.apiguardian:apiguardian-api:jar:1.1.2:test
[INFO] | +- org.junit.jupiter:junit-jupiter-params:jar:5.11.4:test
[INFO] | \- org.junit.jupiter:junit-jupiter-engine:jar:5.11.4:test
[INFO] | \- org.junit.platform:junit-platform-engine:jar:1.11.4:test
[INFO] \- org.mockito:mockito-junit-jupiter:jar:4.11.0:test
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.714 s
[INFO] Finished at: 2025-09-09T09:59:47+08:00
[INFO] ------------------------------------------------------------------------
Comment From: noear
从现有异常看,有 AotProcessor 和 ReflectConfigMetadataRepository 字样。。。推测:是在 aot 运行时,收集类元数据时,被扫描进来了。
之前有类似的经验:在试验 mybatis-plus 原生编译时,明明没有用到过 kotlin 的类,但是原生编译时出错了。(其实在它的基础接口的方法上,有相关的参数。在需要查找哪些需要元数据注册的类时,就被扫进去了)
Comment From: zrlw
org.apache.dubbo:dubbo:jar:3.3.5:compile
you should not depend on it directly, you'd better refer to dubbo-samples-native-image
of dubbo-samples to depend each dubbo sub modules which you need.
Comment From: noear
好,我看下你讲的 dubbo-samples-native-image
我上面提供的示例,已做了简化。。。清理了与 dubbo 无关的内容。
Comment From: noear
@zrlw
示例项目用了:dubbo-spring-boot-starter,所以肯定不会缺 spring 相关的类。。。对“非 spring”项目的这个异常,没啥参考意义。
你们可以提供一个纯 java main + dubbo 运行的原生编译示例。这样就有参考意义了。。。而且 dubbo3 本意也是去 spring 的大重构。。。也是需要这种示例做验证(是否去 spring 干净了?)。
Comment From: zrlw
it is just a reference that how to add dubbo sub modules to build dubbo native image, you should add the minimum modules that you need and does not copy those spring modules. BTW, we require all discussion content should be written in english, you should admire this requirement.
Comment From: noear
问题还没解决呢。怎么就关啦?
//ps: 我不会英文啊。
Comment From: zrlw
问题还没解决呢。怎么就关啦?
//ps: 我不会英文啊。
there are some tranlation tools such as https://fanyi.baidu.com/
Comment From: zrlw
Here is a global opensource community under Apache.org, all the codes and replies are provided by volunteers. If you want to solve your issue immediately, may be you should search some cosulting firm to help you.