Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring boot 使用带Spring boot的外挂时,将URL加倍_Spring Boot_Spring Cloud Feign - Fatal编程技术网

Spring boot 使用带Spring boot的外挂时,将URL加倍

Spring boot 使用带Spring boot的外挂时,将URL加倍,spring-boot,spring-cloud-feign,Spring Boot,Spring Cloud Feign,我对SpringBoot不太熟悉,我正在使用假Rest客户机与我的web服务对话。但是我的URL增加了一倍,无法调用预期的服务 @FeignClient(name= "exchange-service", url="localhost:8000") 公共接口ExchangeServiceProxy{ @GetMapping @RequestMapping(value = "/exchange/from/{from}/to/{to}") public ExchangeBean retrieveE

我对SpringBoot不太熟悉,我正在使用假Rest客户机与我的web服务对话。但是我的URL增加了一倍,无法调用预期的服务

@FeignClient(name= "exchange-service", url="localhost:8000")
公共接口ExchangeServiceProxy{

@GetMapping
@RequestMapping(value = "/exchange/from/{from}/to/{to}")
public ExchangeBean retrieveExchangeValue(@PathVariable("from") String from,
        @PathVariable("to") String to);
}


您需要在主类中的
@springbootplication
之后添加
@enablefignclients
,如下所示:

@SpringBootApplication
@ComponentScan
@EnableScheduling
@EnableAsync
@EnableZuulProxy
@EnableFeignClients
public class ExampleApplication extends SpringBootServletInitializer{
    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }


}
然后为
佯装客户端
创建如下界面:

@FeignClient(name = "service_name", url = "http://localhost:port_to_the_another_application")
public interface ExampleFeignClient {

    @RequestMapping(value = "/mapping", method = RequestMethod.POST)
    String createUserWallet(@RequestHeader("Authorization") String jwtToken);
}

我希望这会有所帮助

您需要在
@springbootplication
之后的主类中添加
@enablefignclients
,如下所示:

@SpringBootApplication
@ComponentScan
@EnableScheduling
@EnableAsync
@EnableZuulProxy
@EnableFeignClients
public class ExampleApplication extends SpringBootServletInitializer{
    public static void main(String[] args) {
        SpringApplication.run(ExampleApplication.class, args);
    }


}
然后为
佯装客户端
创建如下界面:

@FeignClient(name = "service_name", url = "http://localhost:port_to_the_another_application")
public interface ExampleFeignClient {

    @RequestMapping(value = "/mapping", method = RequestMethod.POST)
    String createUserWallet(@RequestHeader("Authorization") String jwtToken);
}

我希望这会有所帮助

你的问题中没有提到你的春季入门课程。如果您使用的是从外部到客户端的负载平衡@enablefignclients足以放入Spring starter类中。我认为您已经将@GetMapping和@RequestMapping都放在了ExchangeServiceProxy中,这是不必要的。请删除@GetMapping,因为您已经在@RequestMapping中给出了url模式。这可能会导致您的url翻一番

@FeignClient(name= "exchange-service", url="localhost:8000")
public interface ExchangeServiceProxy {

@RequestMapping(value = "/exchange/from/{from}/to/{to}")
public ExchangeBean retrieveExchangeValue(@PathVariable("from") String 
from,
        @PathVariable("to") String to);
}

如果您使用像url=“localhost:8000”这样的硬编码,那么它将只命中在端口8000下运行的实例。如果您的意图与我提到的相同,那么使用Ribbon和Eureka命名服务器来充分利用客户端负载平衡将是理想的选择。

您还没有将Spring Starter类放在您的问题中。如果您使用的是从外部到客户端的负载平衡@enablefignclients足以放入Spring starter类中。我认为您已经将@GetMapping和@RequestMapping都放在了ExchangeServiceProxy中,这是不必要的。请删除@GetMapping,因为您已经在@RequestMapping中给出了url模式。这可能会导致您的url翻一番

@FeignClient(name= "exchange-service", url="localhost:8000")
public interface ExchangeServiceProxy {

@RequestMapping(value = "/exchange/from/{from}/to/{to}")
public ExchangeBean retrieveExchangeValue(@PathVariable("from") String 
from,
        @PathVariable("to") String to);
}
如果您使用像url=“localhost:8000”这样的硬编码,那么它将只命中在端口8000下运行的实例。如果您的意图正是我所提到的,那么最好使用Ribbon和Eureka命名服务器来充分利用客户端负载平衡