怎么解决java.lang.NoClassDefFoundError错误

在练习springcloud的gateway网关的时候,服务能启动成功
但是请求的时候一直报NoClassDefFoundError,
我以为是配置问题,但是配置也好像没啥问题
配置如下:

server:
  port: 9527

spring:
  application:
    name: cloud-gateway
  cloud:
    gateway:
      discovery:
        locator:
          enabled: true #开启从注册中心动态创建路由的功能,利用微服务名进行路由
      routes:
        - id: payment_routh #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名
          uri: http://localhost:8001          #匹配后提供服务的路由地址
          #uri: lb://cloud-payment-service #匹配后提供服务的路由地址
          predicates:
            - Path=/payment/get/**         # 断言,路径相匹配的进行路由

        - id: payment_routh2 #payment_route    #路由的ID,没有固定规则但要求唯一,建议配合服务名
          uri: http://localhost:8001          #匹配后提供服务的路由地址
          #uri: lb://cloud-payment-service #匹配后提供服务的路由地址
          predicates:
            - Path=/payment/lb/**         # 断言,路径相匹配的进行路由
            #- After=2020-02-21T15:51:37.485+08:00[Asia/Shanghai]
            #- Cookie=username,zzyy
            #- Header=X-Request-Id, \d+  # 请求头要有X-Request-Id属性并且值为整数的正则表达式

eureka:
  instance:
    hostname: cloud-gateway-service
  client: #服务提供者provider注册进eureka服务列表内
    service-url:
      register-with-eureka: true
      fetch-registry: true
      defaultZone: http://eureka7001.com:7001/eureka

试了半天,发现还是依赖有问题。
gateway要求删除web依赖
在这里插入图片描述
删除:
在这里插入图片描述
但是我删除完了,还是报错…

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

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.cloud.gateway.config.GatewayAutoConfiguration$NettyConfiguration.gatewayHttpClient(GatewayAutoConfiguration.java:597)

The following method did not exist:

    reactor.netty.resources.ConnectionProvider.elastic(Ljava/lang/String;Ljava/time/Duration;)Lreactor/netty/resources/ConnectionProvider;

The method's class, reactor.netty.resources.ConnectionProvider, is available from the following locations:

    jar:file:/E:/mavenRepository/io/projectreactor/netty/reactor-netty/0.9.3.RELEASE/reactor-netty-0.9.3.RELEASE.jar!/reactor/netty/resources/ConnectionProvider.class

It was loaded from the following location:

    file:/E:/mavenRepository/io/projectreactor/netty/reactor-netty/0.9.3.RELEASE/reactor-netty-0.9.3.RELEASE.jar


Action:

Correct the classpath of your application so that it contains a single, compatible version of reactor.netty.resources.ConnectionProvider

此时我是依赖了gateway的

		<dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-gateway</artifactId>
        </dependency>

去网上查了说是Reactor Netty 这个版本不对
在这里插入图片描述
然后去maven仓库里找了

<!--    解决jar包不一致-->
        <dependency>
            <groupId>io.projectreactor.netty</groupId>
            <artifactId>reactor-netty</artifactId>
            <version>0.9.12.RELEASE</version>
        </dependency>

然后启动就不报错了,但是去地址请求的时候,java.lang.NoClassDefFoundError出现了。
在这里插入图片描述
然后把reactor-netty的版本换成:

<version>0.9.7.RELEASE</version>

成功了:
在这里插入图片描述

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值