alibaba / spring-cloud-alibaba

Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
https://sca.aliyun.com
Apache License 2.0
27.47k stars 8.19k forks source link

Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found. #1902

Closed LiHanGod closed 3 years ago

LiHanGod commented 3 years ago

Describe the bug Package name hierarchy problem,com or com.xxxx

Using the com hierarchy com包名

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found.

Action:

Consider defining a bean of type 'com.netflix.client.config.IClientConfig' in your configuration.

Using the com.xxxx hierarchy com.xxx包名

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.2.12.RELEASE)

2021-01-07 10:36:11.349  INFO 12936 --- [  restartedMain] com.xxxx.OrderNacosMain83                : No active profile set, falling back to default profiles: default
2021-01-07 10:36:12.314  WARN 12936 --- [  restartedMain] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'nacos-discovery' contains invalid characters, please migrate to a valid format.
2021-01-07 10:36:12.627  WARN 12936 --- [  restartedMain] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2021-01-07 10:36:12.816  INFO 12936 --- [  restartedMain] o.s.cloud.context.scope.GenericScope     : BeanFactory id=46a0ea06-4267-35b8-b400-145b3c52f871
2021-01-07 10:36:13.625  INFO 12936 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 83 (http)
2021-01-07 10:36:13.642  INFO 12936 --- [  restartedMain] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-01-07 10:36:13.643  INFO 12936 --- [  restartedMain] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-07 10:36:13.816  INFO 12936 --- [  restartedMain] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-01-07 10:36:13.816  INFO 12936 --- [  restartedMain] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2438 ms
2021-01-07 10:36:14.135  WARN 12936 --- [  restartedMain] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-01-07 10:36:14.136  INFO 12936 --- [  restartedMain] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-01-07 10:36:14.143  WARN 12936 --- [  restartedMain] c.n.c.sources.URLConfigurationSource     : No URLs will be polled as dynamic configuration sources.
2021-01-07 10:36:14.143  INFO 12936 --- [  restartedMain] c.n.c.sources.URLConfigurationSource     : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2021-01-07 10:36:14.381  INFO 12936 --- [  restartedMain] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2021-01-07 10:36:14.777  INFO 12936 --- [  restartedMain] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService 'Nacos-Watch-Task-Scheduler'
2021-01-07 10:36:15.225  INFO 12936 --- [  restartedMain] o.s.b.d.a.OptionalLiveReloadServer       : LiveReload server is running on port 35729
2021-01-07 10:36:15.422  INFO 12936 --- [  restartedMain] o.s.b.a.e.web.EndpointLinksResolver      : Exposing 2 endpoint(s) beneath base path '/actuator'
2021-01-07 10:36:15.846  INFO 12936 --- [  restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 83 (http) with context path ''
2021-01-07 10:36:15.952  INFO 12936 --- [  restartedMain] c.a.c.n.registry.NacosServiceRegistry    : nacos registry, DEFAULT_GROUP nacos-order-consumer 192.168.43.2:83 register finished
2021-01-07 10:36:16.092  INFO 12936 --- [  restartedMain] com.xxxx.OrderNacosMain83                : Started OrderNacosMain83 in 6.187 seconds (JVM running for 6.97)

How to Reproduce

  1. Create Maven project
  2. to configure pom.xml
  3. run spring boot application

config

parent POM.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com</groupId>
        <artifactId>stu-alibaba</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>cloudalibaba-consumer-nacos-order83</artifactId>

    <dependencies>
        <!--SpringCloud ailibaba nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

cloudalibaba-consumer-nacos-order83 pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com</groupId>
        <artifactId>stu-alibaba</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>cloudalibaba-consumer-nacos-order83</artifactId>

    <dependencies>
        <!--SpringCloud ailibaba nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>
HaojunRen commented 3 years ago

Is it related with spring-boot-devtools?

LiHanGod commented 3 years ago

I took it out spring-boot-devtools

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>com</groupId>
        <artifactId>stu-alibaba</artifactId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <artifactId>cloudalibaba-consumer-nacos-order83</artifactId>

    <dependencies>
        <!--SpringCloud ailibaba nacos -->
        <dependency>
            <groupId>com.alibaba.cloud</groupId>
            <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
<!--        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-devtools</artifactId>
            <scope>runtime</scope>
            <optional>true</optional>
        </dependency> -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
    </dependencies>
</project>

this is run log:


  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::       (v2.2.12.RELEASE)

2021-01-08 09:27:17.481  INFO 6048 --- [           main] com.OrderNacosMain83                     : No active profile set, falling back to default profiles: default
2021-01-08 09:27:20.920  WARN 6048 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'nacos-discovery' contains invalid characters, please migrate to a valid format.
2021-01-08 09:27:21.236  WARN 6048 --- [           main] o.s.boot.actuate.endpoint.EndpointId     : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2021-01-08 09:27:21.507  INFO 6048 --- [           main] o.s.cloud.context.scope.GenericScope     : BeanFactory id=a1add1cf-819c-3286-b6c6-0fc1ad17e13b
2021-01-08 09:27:22.122  INFO 6048 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 83 (http)
2021-01-08 09:27:22.145  INFO 6048 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2021-01-08 09:27:22.146  INFO 6048 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.41]
2021-01-08 09:27:22.409  INFO 6048 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2021-01-08 09:27:22.410  INFO 6048 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 4894 ms
2021-01-08 09:27:22.802  WARN 6048 --- [           main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'ribbonServerList' defined in class path resource [com/alibaba/cloud/nacos/ribbon/NacosRibbonClientConfiguration.class]: Unsatisfied dependency expressed through method 'ribbonServerList' parameter 0; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.client.config.IClientConfig' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {}
2021-01-08 09:27:22.808  INFO 6048 --- [           main] o.apache.catalina.core.StandardService   : Stopping service [Tomcat]
2021-01-08 09:27:22.849  INFO 6048 --- [           main] ConditionEvaluationReportLoggingListener : 

Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2021-01-08 09:27:23.134 ERROR 6048 --- [           main] o.s.b.d.LoggingFailureAnalysisReporter   : 

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of method ribbonServerList in com.alibaba.cloud.nacos.ribbon.NacosRibbonClientConfiguration required a bean of type 'com.netflix.client.config.IClientConfig' that could not be found.

Action:

Consider defining a bean of type 'com.netflix.client.config.IClientConfig' in your configuration.
HaojunRen commented 3 years ago

参考如下原因

  1. Spring Boot/Spring Cloud/Spring Cloud Alibaba这三者版本是否对齐?
  2. 是否对Ribbon有过自定义的操作?

是否可以提供一个简单的demo以供复现你的问题?

LiHanGod commented 3 years ago

我写了一个demo spring-cloud: Hoxton.SR9 spring-boot: 2.2.12.RELEASE spring-cloud-alibaba: 2.2.3.RELEASE JDK:15.0.1 按照手册应该是版本对齐了 这个demo没有添加自定义的配置,只有一个启动类,启动还是会有这个问题 demo

HaojunRen commented 3 years ago

无法查看查看你的压缩文件,是否直接提供github地址?

HaojunRen commented 3 years ago

还有一个,盲猜,是否跟java 15这么高的版本有关系?我们一般都是在java8下验收的

LiHanGod commented 3 years ago

我使用了JDK1.8进行测试,依然同样的错误 这个是项目的Git地址 https://github.com/LiHanGod/cloud-alibaba-demo

HaojunRen commented 3 years ago

Spring Boot版本升级到2.3.8.RELEASE试试,怀疑SR9不支持2.2

LiHanGod commented 3 years ago

我使用1.8JDK测试Spring Boot 2.3.8.RELEASE,一样😂 单层级的包名就会有问题,多层级的包名就不会有问题,应该不是配置问题了

LiHanGod commented 3 years ago

我的Git已经提交了

HaojunRen commented 3 years ago

大概知道原因了,你的包名用com,应该是不行的,换成com.abc

HaojunRen commented 3 years ago

如果把com作为包名,它会以com作为扫描目录,不仅会增加扫描配置,也会遇到意想不到的问题。建议写demo.业尽量严谨一些

LiHanGod commented 3 years ago

单层级的包名是可以的了,我刚才改成abc的包名,确实可以启动,使用com是不行的,好的谢谢了

SaberLi123 commented 1 year ago

单层级的包名是可以的了,我刚才改成abc的包名,确实可以启动,使用com是不行的,好的谢谢了

这个错误的原因是什么 我也刚刚遇到这个问题

bladetom commented 1 year ago

我也遇到了这个问题,之前写的是com.alibaba包名,改掉就可以了