Nanda
Nanda

Reputation: 21

Feign client errors out when used with ribbon/eureka

@Component
@EnableFeignClients
public class ABCClientApp {

    @Autowired
    ABCClient client;

    public TenantClientApp() {
        // TODO Auto-generated constructor stub
    }

    public ABC getABC(String abcId) {
        return client.getABC(abcId);
    }

    @FeignClient("abc-service")
    public interface ABCClient {

        @RequestMapping(method = RequestMethod.GET, value = "/abc/{abcId}")
        ABC getABC(@PathVariable("abcId") String abcId);

    }

}

and following is the test for the above class:

@Configuration
@EnableDiscoveryClient
@ComponentScan("com.abc.client.rest")
@EnableAutoConfiguration(exclude={org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration.class,org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration.class})
@SpringApplicationConfiguration(classes=ABCClientAppTest.class)
public class ABCClientAppTest extends AbstractTestNGSpringContextTests{

    @Autowired
    ABCClientApp app;

    @Test
    public void test_getABC() {
        String abcId = "250449AD17E1";
        app.getABC(abcId);
    }

}

When I run the test using TestNG the following error is thrown:

com.netflix.client.ClientException: Load balancer does not have available server for client: abc-service

Eureka server is configured to find config server. application.yml of eureka server is as follows:

info:
  description: Eureka Service Registry

server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

security:
  user:
    password: password

and bootstrap.yml is as follows:

spring:
  application:
    name: eureka
  cloud:
    config:
      enabled: false

The config server, eureka server and abc-service is run as spring boot app before running the above test. abc-service registers itself with Eureka when it starts up.

Upvotes: 2

Views: 3769

Answers (1)

user1075613
user1075613

Reputation: 744

Your client ABCClientAppTest must register with an application name :

@SpringApplicationConfiguration(name="abc-service")

which is used by FeignClient

Upvotes: 1

Related Questions