• 刚开始学SpringCloud的Eureka带来的问题


    关注 码龄 粉丝数 原力等级 -- 被采纳 被点赞 采纳率 汪的爱琪 2024-06-04 11:22 采纳率: 67.5% 浏览 52 首页/ 大数据 / 刚开始学SpringCloud的Eureka带来的问题 eurekaspring cloudmaven 报错信息 . ____ _ __ _ _ /\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \ ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \ \\/ ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |_\__, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v3.2.6) 2024-06-04T11:20:14.488+08:00 INFO 18700 --- [user-server] [ main] o.h.userserver.UserServerApplication : Starting UserServerApplication using Java 17.0.10 with PID 18700 (D:\DevCraftOrders\DevCraftOrders\user-server\target\classes started by 汪海洋 in D:\DevCraftOrders\DevCraftOrders) 2024-06-04T11:20:14.490+08:00 INFO 18700 --- [user-server] [ main] o.h.userserver.UserServerApplication : No active profile set, falling back to 1 default profile: "default" 2024-06-04T11:20:15.262+08:00 INFO 18700 --- [user-server] [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=586ec15a-30c8-3293-b11e-926d2f7ba1c8 2024-06-04T11:20:15.396+08:00 WARN 18700 --- [user-server] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration$DeferringLoadBalancerInterceptorConfig' of type [org.springframework.cloud.client.loadbalancer.LoadBalancerAutoConfiguration$DeferringLoadBalancerInterceptorConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). The currently created BeanPostProcessor [lbRestClientPostProcessor] is declared through a non-static factory method on that class; consider declaring it as static instead. 2024-06-04T11:20:15.397+08:00 WARN 18700 --- [user-server] [ main] trationDelegate$BeanPostProcessorChecker : Bean 'deferringLoadBalancerInterceptor' of type [org.springframework.cloud.client.loadbalancer.DeferringLoadBalancerInterceptor] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying). Is this bean getting eagerly injected into a currently created BeanPostProcessor [lbRestClientPostProcessor]? Check the corresponding BeanPostProcessor declaration and its dependencies. 2024-06-04T11:20:15.574+08:00 INFO 18700 --- [user-server] [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port 8081 (http) 2024-06-04T11:20:15.582+08:00 INFO 18700 --- [user-server] [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2024-06-04T11:20:15.582+08:00 INFO 18700 --- [user-server] [ main] o.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/10.1.24] 2024-06-04T11:20:15.633+08:00 INFO 18700 --- [user-server] [ main] o.a.c.c.C.[Tomcat].[localhost].[/user] : Initializing Spring embedded WebApplicationContext 2024-06-04T11:20:15.633+08:00 INFO 18700 --- [user-server] [ main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 1114 ms 2024-06-04T11:20:16.898+08:00 WARN 18700 --- [user-server] [ main] iguration$LoadBalancerCaffeineWarnLogger : Spring Cloud LoadBalancer is currently working with the default cache. While this cache implementation is useful for development and tests, it's recommended to use Caffeine cache in production.You can switch to using Caffeine cache, by adding it and org.springframework.cache.caffeine.CaffeineCacheManager to the classpath. 2024-06-04T11:20:16.903+08:00 INFO 18700 --- [user-server] [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 1 endpoint(s) beneath base path '/actuator' 2024-06-04T11:20:16.958+08:00 INFO 18700 --- [user-server] [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING 2024-06-04T11:20:16.960+08:00 ERROR 18700 --- [user-server] [ main] o.s.c.n.e.s.EurekaRegistration : error getting CloudEurekaClient org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'scopedTarget.eurekaClient' defined in class path resource [org/springframework/cloud/netflix/eureka/EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.class]: Unsatisfied dependency expressed through method 'eurekaClient' parameter 3: No qualifying bean of type 'com.netflix.discovery.shared.transport.jersey.TransportClientFactories' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:795) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:542) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1337) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1167) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:562) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:522) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:376) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:375) ~[spring-cloud-context-4.1.3.jar:4.1.3] at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:179) ~[spring-cloud-context-4.1.3.jar:4.1.3] at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:373) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:200) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) ~[spring-aop-6.1.8.jar:6.1.8] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:128) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:116) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] 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.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:281) ~[spring-core-6.1.8.jar:6.1.8] at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:482) ~[spring-cloud-context-4.1.3.jar:4.1.3] at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:184) ~[spring-aop-6.1.8.jar:6.1.8] at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:768) ~[spring-aop-6.1.8.jar:6.1.8] at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:720) ~[spring-aop-6.1.8.jar:6.1.8] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$SpringCGLIB$$0.getEurekaClient() ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:83) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:66) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:89) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:471) ~[spring-context-6.1.8.jar:6.1.8] at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:260) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:205) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:981) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.2.6.jar:3.2.6] at org.haiyang.userserver.UserServerApplication.main(UserServerApplication.java:11) ~[classes/:na] Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.netflix.discovery.shared.transport.jersey.TransportClientFactories' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1880) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1406) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1353) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.ConstructorResolver.resolveAutowiredArgument(ConstructorResolver.java:904) ~[spring-beans-6.1.8.jar:6.1.8] at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:782) ~[spring-beans-6.1.8.jar:6.1.8] ... 40 common frames omitted 2024-06-04T11:20:16.965+08:00 WARN 18700 --- [user-server] [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration' 2024-06-04T11:20:16.986+08:00 INFO 18700 --- [user-server] [ main] .s.b.a.l.ConditionEvaluationReportLogger : Error starting ApplicationContext. To display the condition evaluation report re-run your application with 'debug' enabled. 2024-06-04T11:20:16.998+08:00 ERROR 18700 --- [user-server] [ main] o.s.boot.SpringApplication : Application run failed org.springframework.context.ApplicationContextException: Failed to start bean 'eurekaAutoServiceRegistration' at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:291) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:471) ~[spring-context-6.1.8.jar:6.1.8] at java.base/java.lang.Iterable.forEach(Iterable.java:75) ~[na:na] at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:260) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:205) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:981) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:627) ~[spring-context-6.1.8.jar:6.1.8] at org.springframework.boot.web.servlet.context.ServletWebServerApplicationContext.refresh(ServletWebServerApplicationContext.java:146) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:754) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:456) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1363) ~[spring-boot-3.2.6.jar:3.2.6] at org.springframework.boot.SpringApplication.run(SpringApplication.java:1352) ~[spring-boot-3.2.6.jar:3.2.6] at org.haiyang.userserver.UserServerApplication.main(UserServerApplication.java:11) ~[classes/:na] Caused by: java.lang.NullPointerException: Cannot invoke "org.springframework.cloud.netflix.eureka.CloudEurekaClient.getApplications()" because the return value of "org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient()" is null at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:83) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:66) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:89) ~[spring-cloud-netflix-eureka-client-4.1.2.jar:4.1.2] at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:288) ~[spring-context-6.1.8.jar:6.1.8] ... 13 common frames omitted Process finished with exit code 1 为了尝试学习Eureka,我建立了如下结构的项目而eureka我已经配置的服务端可以访问了 配置服务端的yml文件 server: port: 8077 servlet: context-path: / eureka: client: register-with-eureka: false fetch-registry: false spring: application: name: eureka-server config: activate: on-profile: dev 但是对于客户端我怎么都没办法配置首先,我在父pom中导入了eureka的客户端依赖 4.0.0 org.springframework.boot spring-boot-starter-parent 3.2.6 org.haiyang DevCraftOrders 1.0-SNAPSHOT pom 17 17 UTF-8 2023.0.2 eureka-server order-server user-server org.springframework.cloud spring-cloud-dependencies ${spring-cloud.version} pom import org.springframework.boot spring-boot-starter org.springframework.boot spring-boot-starter-test test com.mysql mysql-connector-j runtime org.mybatis.spring.boot mybatis-spring-boot-starter 3.0.3 org.projectlombok lombok annotationProcessor org.mybatis.spring.boot mybatis-spring-boot-starter-test 3.0.3 test org.springframework.boot spring-boot-starter-web org.springframework.cloud spring-cloud-starter-netflix-eureka-server org.springframework.cloud spring-cloud-starter-netflix-eureka-client org.springframework.boot spring-boot-maven-plugin 然后利用继承和聚合,所有的子模块都继承了父模块的依赖,也就是说对于其中一个user-server模块来说 4.0.0 org.haiyang DevCraftOrders 1.0-SNAPSHOT user-server 0.0.1-SNAPSHOT user-server user-server 但是在user-server模块的启动类中却根本就没有@EnableEurekaClient注解,另外显示子模块maven已经导入了这个模块了 另外user-service的配置是 spring: application: name: user-service version: 1.0.0 datasource: url: jdbc:mysql://39.106.45.185:3306/user_db?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=Asia/Shanghai username: root password: 1234 driver-class-name: com.mysql.cj.jdbc.Driver mybatis: type-aliases-package: org.haiyang.userserver.pojo mapper-locations: classpath:mapper/*.xml server: port: 8081 servlet: context-path: /user eureka: client: # register-with-eureka: false # fetch-registry: false instance: hostname: 127.0.0.1 port: 9000 service-url: defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/ 展开全部 收起 写回答 好问题 0 提建议 追加酬金 关注问题 微信扫一扫 点击复制链接 分享 邀请回答 编辑 收藏 删除 结题 收藏 举报 追加酬金 (90%的用户在追加酬金后获得了解决方案) 当前问题酬金 ¥ 0 (可追加 ¥500) ¥ 15¥ 20¥ 50¥ 100¥ 200 支付方式 扫码支付 二维码出错 点击刷新 支付金额 15 元 提供问题酬金的用户不参与问题酬金结算和分配 支付即为同意 《付费问题酬金结算规则》 结题 再想想 删除 再等等

    2条回答 默认 最新

    • 阿里嘎多学长 2024-06-04 11:22
      关注

      以下内容由CHATGPT及阿里嘎多学长共同生成、有用望采纳:


      【解题思路】:检查Eureka配置和网络设置,确保服务注册和发现正常。

      评论
    • 专家-赤兔[在线] 全栈领域优质创作者 2024-06-04 11:22
      关注

      引自免费微信小程序:皆我百晓生

      看起来你在学习Spring Cloud Eureka的过程中遇到了一些问题。让我们一步步解决这些问题。

      首先,关于错误消息中的警告部分,这是由于Spring Cloud LoadBalancer推荐在生产环境中使用Caffeine作为缓存实现。要解决这个问题,你需要添加Caffeine库到你的项目中,并且配置一个CaffeineCacheManager。以下是添加Caffeine到你的用户服务器模块的步骤:

      1. user-server模块的pom.xml文件中,添加Caffeine依赖项:
      
          com.github.ben-manes.caffeine
          caffeine
      
      
      1. 然后创建一个Caffeine Cache Manager配置类,例如CaffeineCacheConfiguration.java
      package org.haiyang.userserver.config;
      
      import org.springframework.cache.caffeine.CaffeineCacheManager;
      import org.springframework.context.annotation.Bean;
      import org.springframework.context.annotation.Configuration;
      
      @Configuration
      public class CaffeineCacheConfiguration {
      
          @Bean
          public CaffeineCacheManager cacheManager() {
              return new CaffeineCacheManager();
          }
      }
      

      接下来,我们处理主错误信息,这是一个UnsatisfiedDependencyException,表示缺少一个依赖注入。根据堆栈跟踪,似乎是因为缺少TransportClientFactories的实例。这通常与Netflix Eureka Client的依赖项不正确有关。

      检查一下你的父级POM文件(DevCraftOrders/pom.xml),确保有正确的依赖版本。确保你没有误删任何相关依赖。这里有一个修复后的父级POM依赖部分示例:

      
          ...
          
              org.springframework.cloud
              spring-cloud-starter-netflix-eureka-client
          
          
          
          ...
      
      

      然后,在你的user-server模块中,确保包含@EnableEurekaClient注解,这样Spring Boot会自动配置Eureka客户端。在UserServerApplication.java中添加它:

      package org.haiyang.userserver;
      
      import org.springframework.boot.SpringApplication;
      import org.springframework.boot.autoconfigure.SpringBootApplication;
      import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
      
      @SpringBootApplication
      @EnableEurekaClient
      public class UserServerApplication {
      
          public static void main(String[] args) {
              SpringApplication.run(UserServerApplication.class, args);
          }
      }
      

      此外,检查application-dev.yml中的Eureka客户端配置。确保你不需要禁用注册和服务目录的获取(默认情况下应该是开启的):

      eureka:
        client:
          register-with-eureka: true
          fetch-registry: true
          instance:
            hostname: 127.0.0.1
            port: 9000
            service-url:
              defaultZone: http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/
      

      注意,如果你的Eureka服务运行在不同的主机上,你需要将hostnameport替换为实际的Eureka服务器地址。

      最后,确保所有模块都使用相同的Spring Cloud版本。在你的父级POM文件中,确认属性设置为一致的值。

      按照上述步骤操作,你应该能解决Eureka客户端的问题并成功启动user-server应用。如果还有其他问题,请随时告诉我。

      展开全部

      评论 编辑记录
    编辑
    预览

    报告相同问题?

  • 相关阅读:
    ALL IN ONE最佳实践方案分享(从硬件到软件全覆盖)
    css、css3、scss的区别与联系
    【毕业设计】基于STM32的空气质量检测仪 - 环境检测盒子 - 单片机 物联网
    HTML静态网页成品作业(HTML+CSS)——动漫海贼王介绍网页(1个页面)
    香港Web3媒体:Techub News
    读书的风景
    分布式存储系统之Ceph集群MDS扩展
    【Spring boot】RedisTemplate中String、Hash、List设置过期时间
    FFplay文档解读-24-音频过滤器九
    Python图像处理库打开图片默认的维度顺序
  • 原文地址:https://ask.csdn.net/questions/8113749