当前位置: 首页 > 知识库问答 >
问题:

在Spring Boot下使用Feygn2时将URL翻倍

沈良策
2023-03-14

我对Spring boot并不陌生,我正在使用假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);

}

 status 404 reading 
ExchangeServiceProxy#retrieveExchangeValue(String,String); content:
{"timestamp":"2018-11-22T05:50:45.822+0000","status":404,"error":"Not 
Found","message":"No message 
available","path":"/exchange/from/USD/to/XYZ/exchange/from/USD/to/XYZ"}

共有2个答案

邢昊焜
2023-03-14

您需要在主类的SpringBootApplication之后添加EnableFeignClients,如下所示:

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

我希望这会有所帮助。

狄阳华
2023-03-14

您还没有将Spring Starter Class放入您的问题中。如果您使用的是客户端负载平衡,那么@EnableFegnClients就足以放入您的Spring Starter class。我认为您已经在ExChangeServiceProxy中同时放入了@GetMap和@Request estMap,这是不必要的。请删除@GetMap,因为您在@Request estMap中给出了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命名服务器来充分利用客户端负载平衡将是理想的。

 类似资料:
  • 目前,我正在尝试将JWT身份验证集成到现有的Spring Boot Webflux项目中。作为模板,我使用了这篇媒体文章:https://medium.com/@ard333/authentication-and-authorization-using-jwt-on-spring-webflux-29b81f813e78。如果我将注释@EnableWebFluxSecurity放在我的WebSec

  • 本文向大家介绍springboot下使用mybatis的方法,包括了springboot下使用mybatis的方法的使用技巧和注意事项,需要的朋友参考一下 使用mybatis-spring-boot-starter即可。 简单来说就是mybatis看见spring boot这么火,于是搞出来mybatis-spring-boot-starter这个解决方案来与springboot更好的集成 详见

  • 我不明白为什么当我对数组进行筛选时,ES会加倍数组中的_id字段。

  • 问题内容: 我正在尝试使用我的应用程序中的URL和按钮下载图像。当我在手机上运行它时,我无法下载该图像。任何人都可以指出这个问题。我在这里先向您的帮助表示感谢 :) 这是我的代码。 问题答案: 您可以通过两种方式从url下载图像 1。您 可以使用Glide库从url加载图像,看下面的代码,它可以轻松地为您提供帮助 编译这个库 而不是像这样加载图像 2。如果您不想使用第三方库,请尝试此 创建一个异步

  • 我尝试设置一个完整的路径,如: 但在这里,reverfit没有看到路径实际上是完整的URL,并且正在尝试下载 有任何提示,我可以如何使用这样的动态url改造?

  • 本文向大家介绍SpringBoot使用POI进行Excel下载,包括了SpringBoot使用POI进行Excel下载的使用技巧和注意事项,需要的朋友参考一下 本文实例为大家分享了SpringBoot使用POI进行Excel下载的具体代码,供大家参考,具体内容如下 使用poi处理Excel特别方便,此处将处理Excel的代码分享出来。 1.maven引用 2.service逻辑代码 3.contr