0

I am little new to Spring boot and I am using Feign Rest client to talk to my web service. But I'm getting my URL double and cannot invoke the intended service.

@FeignClient(name= "exchange-service", url="localhost:8000")

public interface 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"}
Kepler
  • 399
  • 1
  • 7
  • 19

2 Answers2

2

You haven't put your Spring Starter Class in your question. If you are using Feign to client side load balancing @EnableFeignClients is enough to put in your Spring starter class. I think you have put both @GetMapping and @RequestMapping in your ExchangeServiceProxy which is unnecessary. Please remove @GetMapping since you have given the url pattern within the @RequestMapping. This might caused to double your 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);
}

If you have hard coded like url="localhost:8000" then it will hit only to the instance that is running under the port 8000. It would be ideal to use Ribbon and Eureka naming server to get the full use of client side load balancing if your intention is what I have mentioned.

Dilan
  • 1,389
  • 5
  • 14
  • 24
0

You need to add @EnableFeignClients in main class after @SpringBootApplication Like this:

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


}

And then Create an Interface for FeignClient like this:

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

I hope this will help.

Pawan Tiwari
  • 518
  • 6
  • 26