Java 与ribbon/eureka一起使用时假装客户端错误

Java 与ribbon/eureka一起使用时假装客户端错误,java,spring,netflix-feign,netflix-eureka,Java,Spring,Netflix Feign,Netflix Eureka,以下是对上述类别的测试: @Component @EnableFeignClients public class ABCClientApp { @Autowired ABCClient client; public TenantClientApp() { // TODO Auto-generated constructor stub } public ABC getABC(String abcId) { return

以下是对上述类别的测试:

@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);

    }

}
当我使用TestNG运行测试时,抛出以下错误:

com.netflix.client.ClientException:负载平衡器没有可用于客户端的服务器:abc服务

Eureka服务器配置为查找配置服务器application.yml如下:

@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);
    }

}

在运行上述测试之前,配置服务器、eureka服务器和abc服务将作为spring boot应用程序运行。abc服务在启动时向Eureka注册。

您的客户ABCClientAppTest必须使用应用程序名称注册:

@SpringApplicationConfiguration(name=“abc服务”)

这是由FaignClient使用的

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