ron
ron

Reputation: 1

openfeign fallbackFactory for springcloud version 2023.0.3 cannot be downgraded

I configured a openFeign FallbackFactory for a romote invoke,but it doesn't work when remote service is exception and return 500; Does anyone have the problem?

response:

{
  "timestamp": "2024-12-31T08:44:53.131+00:00",
  "status": 500,
  "error": "Internal Server Error",
  "path": "/demo/port"
}

this is error info:

2024-12-31T16:44:53.129+08:00 ERROR 68881 --- [material-audience] [nio-7941-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: feign.FeignException$InternalServerError: [500] during [GET] to [http://material-tsp/health/port\] [DemoClient#port()]: [{"timestamp":"2024-12-31T08:44:53.125+00:00","status":500,"error":"Internal Server Error","path":"/health/port"}]] with root cause

feign.FeignException$InternalServerError: [500] during [GET] to [http://material-tsp/health/port\] [DemoClient#port()]: [{"timestamp":"2024-12-31T08:44:53.125+00:00","status":500,"error":"Internal Server Error","path":"/health/port"}] at feign.FeignException.serverErrorStatus(FeignException.java:259) ~[feign-core-13.3.jar:na] at feign.FeignException.errorStatus(FeignException.java:206) ~[feign-core-13.3.jar:na] 

pom.xml

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>3.3.3</version>
    </parent>

    <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>2023.0.3</version>
        <type>pom</type>
        <scope>import</scope>
    </dependency>

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

DemoClient:

package com.link.code.materialaudience.openfeign;

import com.link.code.materialaudience.openfeign.fallback.RemoteDemoFallbackFactory;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.GetMapping;

@FeignClient(value = "material-tsp",fallbackFactory = RemoteDemoFallbackFactory.class)
public interface DemoClient {

    @GetMapping("health/port")
    String port();
}

RemoteDemoFallbackFactory:

package com.link.code.materialaudience.openfeign.fallback;

import com.link.code.materialaudience.openfeign.DemoClient;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class RemoteDemoFallbackFactory implements FallbackFactory<DemoClient> {
    @Override
    public DemoClient create(Throwable cause) {
        return new DemoClient() {
            @Override
            public String port() {
                log.info("invoke service fail:{},",cause.toString(),cause);
                return "exception---null";
            }
        };
    }
}

1,I want to know where is wrong 2,Why does is appear

Upvotes: 0

Views: 15

Answers (0)

Related Questions