apache / shenyu

Apache ShenYu is a Java native API Gateway for service proxy, protocol conversion and API governance.
https://shenyu.apache.org/
Apache License 2.0
8.43k stars 2.93k forks source link

Got ClassNotFoundException while start my Gateway in 2.4.8 spring boot #1693

Closed ichenhe closed 3 years ago

ichenhe commented 3 years ago

Describe the bug

I have followed the guide to built my gateway project. But it failed to start and said java.lang.ClassNotFoundException: reactor.netty.tcp.ProxyProvider$TypeSpec.

By the way, the doc says shenyu's maven uri is org.apache.shenyu:shenyu-xxx, but the actual is org.dromara:soul-xxx, which is very confusing.

Environment

My dependencies:

dependencies {
    implementation("org.springframework.boot:spring-boot-starter-webflux")
    implementation("org.springframework.boot:spring-boot-starter-actuator")
    implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
    implementation("org.jetbrains.kotlin:kotlin-reflect")
    implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
    kapt("org.springframework.boot:spring-boot-configuration-processor")

    // shenyu
    implementation("org.dromara:soul-spring-boot-starter-gateway:${Const.shenYuVersion}")
    implementation("org.dromara:soul-spring-boot-starter-sync-data-websocket:${Const.shenYuVersion}")

    // shenyu spring cloud
    implementation("org.dromara:soul-spring-boot-starter-plugin-springcloud:${Const.shenYuVersion}")
    implementation("org.dromara:soul-spring-boot-starter-plugin-httpclient:${Const.shenYuVersion}")
    implementation("org.springframework.cloud:spring-cloud-commons")
    implementation("org.springframework.cloud:spring-cloud-starter-netflix-ribbon")
    implementation("com.alibaba.cloud:spring-cloud-starter-alibaba-nacos-discovery")

}

Steps to reproduce

  1. Follow this to setup my gateway. (start successfully here)
  2. Follow this to add spring cloud support.

Expected behavior

Gateway start successfully.

Debug logs

Click to expand ``` 2021-07-01 00:06:08.896 ERROR 33547 --- [ main] o.s.boot.SpringApplication : Application run failed java.lang.IllegalStateException: Error processing condition on org.dromara.soul.spring.boot.starter.plugin.global.GlobalPluginConfiguration.soulContextBuilder at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:60) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.context.annotation.ConditionEvaluator.shouldSkip(ConditionEvaluator.java:108) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForBeanMethod(ConfigurationClassBeanDefinitionReader.java:193) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitionsForConfigurationClass(ConfigurationClassBeanDefinitionReader.java:153) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.annotation.ConfigurationClassBeanDefinitionReader.loadBeanDefinitions(ConfigurationClassBeanDefinitionReader.java:129) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.annotation.ConfigurationClassPostProcessor.processConfigBeanDefinitions(ConfigurationClassPostProcessor.java:343) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.annotation.ConfigurationClassPostProcessor.postProcessBeanDefinitionRegistry(ConfigurationClassPostProcessor.java:247) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanDefinitionRegistryPostProcessors(PostProcessorRegistrationDelegate.java:311) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.support.PostProcessorRegistrationDelegate.invokeBeanFactoryPostProcessors(PostProcessorRegistrationDelegate.java:112) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.support.AbstractApplicationContext.invokeBeanFactoryPostProcessors(AbstractApplicationContext.java:746) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:564) ~[spring-context-5.3.7.jar:5.3.7] at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:63) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:771) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:763) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:438) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:339) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1329) ~[spring-boot-2.4.6.jar:2.4.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1318) ~[spring-boot-2.4.6.jar:2.4.6] at com.cotwf.wfpserver.WFPGateWayApplicationKt.main(WFPGateWayApplication.kt:13) ~[main/:na] Caused by: java.lang.IllegalStateException: Failed to introspect Class [org.dromara.soul.springboot.starter.plugin.httpclient.HttpClientPluginConfiguration] from ClassLoader [jdk.internal.loader.ClassLoaders$AppClassLoader@368239c8] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:481) ~[spring-core-5.3.7.jar:5.3.7] at org.springframework.util.ReflectionUtils.doWithMethods(ReflectionUtils.java:358) ~[spring-core-5.3.7.jar:5.3.7] at org.springframework.util.ReflectionUtils.getUniqueDeclaredMethods(ReflectionUtils.java:414) ~[spring-core-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.lambda$getTypeForFactoryMethod$2(AbstractAutowireCapableBeanFactory.java:747) ~[spring-beans-5.3.7.jar:5.3.7] at java.base/java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1705) ~[na:na] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:746) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.determineTargetType(AbstractAutowireCapableBeanFactory.java:685) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.predictBeanType(AbstractAutowireCapableBeanFactory.java:656) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.AbstractBeanFactory.isFactoryBean(AbstractBeanFactory.java:1670) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doGetBeanNamesForType(DefaultListableBeanFactory.java:570) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:542) ~[spring-beans-5.3.7.jar:5.3.7] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.collectBeanNamesForType(OnBeanCondition.java:238) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:231) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getBeanNamesForType(OnBeanCondition.java:221) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchingBeans(OnBeanCondition.java:169) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.condition.OnBeanCondition.getMatchOutcome(OnBeanCondition.java:144) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] at org.springframework.boot.autoconfigure.condition.SpringBootCondition.matches(SpringBootCondition.java:47) ~[spring-boot-autoconfigure-2.4.6.jar:2.4.6] ... 18 common frames omitted Caused by: java.lang.NoClassDefFoundError: reactor/netty/tcp/ProxyProvider$Builder at java.base/java.lang.Class.getDeclaredMethods0(Native Method) ~[na:na] at java.base/java.lang.Class.privateGetDeclaredMethods(Class.java:3166) ~[na:na] at java.base/java.lang.Class.getDeclaredMethods(Class.java:2309) ~[na:na] at org.springframework.util.ReflectionUtils.getDeclaredMethods(ReflectionUtils.java:463) ~[spring-core-5.3.7.jar:5.3.7] ... 34 common frames omitted Caused by: java.lang.ClassNotFoundException: reactor.netty.tcp.ProxyProvider$Builder at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581) ~[na:na] at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178) ~[na:na] at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521) ~[na:na] ... 38 common frames omitted ```
dengliming commented 3 years ago

2.3.0 doc: https://shenyu.apache.org/zh/projects/shenyu-2.3.0/spring-cloud-proxy/

JohnChen92 commented 3 years ago

the latest release is soul 2.3.0 you can ues old doc Apache ShenYu(2.3.0) or download current and build it

ichenhe commented 3 years ago

@dengliming Thanks. But it problem still there.

I changed both spring boot and spring cloud version to 2.2.2.RELEASE, the problem was fixed. It seems that soul-spring-boot-starter-plugin-springcloud is not compatible with the latest version of spring boot (cloud).

Is this the intented behavior or a bug that needs to be fixed?

KevinClair commented 3 years ago

Soon after, we will release version 2.4.0, it startes with org.apache.shenyu.

ichenhe commented 3 years ago

Finally, I found out that it is the result of version conflict. For those with the same problems, try to use the version indicated in the document first. For me, I changed the spring cloud componet's version to 2.2.2.RELEASE and the problem was gone.