2

FeingClient Server



@RestController
public class FeinApiCall {
    
    @Autowired
    CustomFeignClient customFeignClient;


    @GetMapping("/getinfothroughfeign")
    public String getFeignLoad() {
        String result =customFeignClient.getInstance();
        return result;
    }
}



@SpringBootApplication
@EnableFeignClients
@RibbonClient(name = "testServer", configuration = CustomIClientfiguration.class)
public class FeignLoadBalancingApplication {

    public static void main(String[] args) {
        SpringApplication.run(FeignLoadBalancingApplication.class, args);
    }

     
}



@FeignClient(name ="testServer")
public interface CustomFeignClient {
     @RequestMapping(method = RequestMethod.GET, value = "/getPort")
     String getInstance();
}


@Configuration
public class CustomIClientfiguration {

    public static final int DEFAULT_CONNECT_TIMEOUT = 1000;
    public static final int DEFAULT_READ_TIMEOUT = 1000;
    
    @Autowired
    IClientConfig ribbonClientConfig;
    
    @Bean
    public IClientConfig ribbonClientConfig() {
        System.err.println("CustomIClientfiguration overiding");
        DefaultClientConfigImpl config = new DefaultClientConfigImpl();
        config.loadProperties("testServer");
        config.set(CommonClientConfigKey.ConnectTimeout, DEFAULT_CONNECT_TIMEOUT);
        config.set(CommonClientConfigKey.ReadTimeout, DEFAULT_READ_TIMEOUT);
        return config;
    }
    
    @Bean
    public IPing ribbonPing(IClientConfig config) {
        return new PingUrl();
    }
    
    @Bean
    public IRule ribbonRule(IClientConfig config) {
        
        return new AvailabilityFilteringRule();
    }
}

application.properties of feignclient server#



server.port=9098

testServer.ribbon.eureka.enabled=true
testServer.ribbon.listOfServers=localhost:2289
testServer.ribbon.ServerListRefreshInterval=15000



testserver files



@RestController
public class TestController {

    @Autowired
    ApplicationContext context;
    
    @Value("${server.port}")
    private String portNumber;
    
    @GetMapping("/getPort")
    public String getString()
    {
        return "Port number "+this.portNumber;
    }
    
    @GetMapping("/")
    public String ping()
    {
        
        return "welcome";
    }
}

application.properties of testServer#


server.port=2289
spring.application.name=testServer
management.endpoints.web.exposure.include=*
management.endpoint.health.enabled=true

Error


Receiver class org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient does not define or inherit an implementation of the resolved method 'abstract org.springframework.cloud.client.ServiceInstance choose(java.lang.String, org.springframework.cloud.client.loadbalancer.Request)' of interface org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser. java.lang.AbstractMethodError: Receiver class org.springframework.cloud.netflix.ribbon.RibbonLoadBalancerClient does not define or inherit an implementation of the resolved method 'abstract org.springframework.cloud.client.ServiceInstance choose(java.lang.String, org.springframework.cloud.client.loadbalancer.Request)' of interface org.springframework.cloud.client.loadbalancer.ServiceInstanceChooser. at org.springframework.cloud.openfeign.loadbalancer.FeignBlockingLoadBalancerClient.execute(FeignBlockingLoadBalancerClient.java:88) at feign.SynchronousMethodHandler.executeAndDecode(SynchronousMethodHandler.java:119) at feign.SynchronousMethodHandler.invoke(SynchronousMethodHandler.java:89) at feign.ReflectiveFeign$FeignInvocationHandler.invoke(ReflectiveFeign.java:100) at jdk.proxy3/jdk.proxy3.$Proxy83.getInstance(Unknown Source) at com.FeignLoadBalancing.api.FeinApiCall.getFeignLoad(FeinApiCall.java:19) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.base/java.lang.reflect.Method.invoke(Method.java:567) at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:197) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:141) at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:106) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1064) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:963) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)

Tarun Singh
  • 97
  • 2
  • 10

2 Answers2

1

I have done following changes in my feignclient server

  1. created new configuration file

@Configuration
public class OpenFeignConfiguration {
    
    @Autowired
    RibbonLoadBalancerClient ribbonLoadBalancerClient;
    
    @Bean
    public Feign.Builder feignBuilder() {
        return Feign.builder();
    }
}
  1. Set my configuration file in feign client

@FeignClient(name ="testServer",configuration = OpenFeignConfiguration.class)
public interface CustomFeignClient {
     @RequestMapping(method = RequestMethod.GET, value = "/getPort")
     String getInstance();
}
  1. Created ChildRibbonLoadBalancerClient which extends RibbonLoadBalancerClient and overrides ServiceInstance choose() method

@Component
public class ChildRibbonLoadBalancerClient extends RibbonLoadBalancerClient{

    @Autowired
    LoadBalancerClient loadBalancerClient;
    
    @Override
    public <T> ServiceInstance choose(String serviceId, Request<T> request) {
         ServiceInstance server = this.loadBalancerClient.choose(serviceId);
         return server;
    }

    public ChildRibbonLoadBalancerClient(SpringClientFactory clientFactory) {
        super(clientFactory);
    }

}
Tarun Singh
  • 97
  • 2
  • 10
-1

I got the same issue and I am suing below Sprigboot and Aprinb cloud versions. I have implemented the above solutions given by "Tarun Singh" and It worked for me. springBootVersion = '2.4.13' springCloudVersion = '2020.0.3'

vijay
  • 1
  • 1
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 28 '21 at 17:42