I\'m trying to use Feign client. Below is my feing client:
import com.eprogrammerz.examples.domain.Movie;
import org.springframework.cloud.netflix.feign.Feig
If your Spring Cloud set up does not support specifying the servers in application.properties/application.yml, you have to configure the services URL in a Configuration class.
Pls, note the warning message in my application.properties [Spring Boot v2.0.0RELEASE, spring-cloud-starter-feign & spring-cloud-starter-ribbon v 1.4.3.RELEASE]
So what I did was to write a Configuration class as follows:
@Configuration
class LocalRibbonClientConfiguration {
@Bean
public ServerList<Server> ribbonServerList() {
// return new ConfigurationBasedServerList();
StaticServerList<Server> staticServerList = new StaticServerList<>((new Server("localhost", 8001)),
new Server("localhost", 8000));
return staticServerList;
}
}
Then, configured the Spring Boot Application to use this configuration as follows:
@SpringBootApplication
@EnableFeignClients("my-package.currencyconversionservice")
@RibbonClient(name = "currency-conversion-service", configuration = LocalRibbonClientConfiguration.class)
public class CurrencyConversionServiceApplication {
// nothing new here...
}
No need to change the Feign Proxy class. Posting just for this post to be served as a complete solution to the problem:
@FeignClient(name="currency-exchange-service")
@RibbonClient(name="currency-exchange-service")
public interface CurrencyExchangeServiceProxy {
@GetMapping("/currency-exchange/from/{from}/to/{to}")
public CurrencyConversionBean retrieveExchangeValue(@PathVariable("from") String from, @PathVariable("to") String to);
}
That's all. The problem was fixed.
You need to add Ribbon along with Eureka Client, otherwise the service won't be fetched.
in my pom.xml I have:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-ribbon</artifactId>
</dependency>
And in my service proxy:
@FeignClient(name = "movie-api")
@RibbonClient(name = "movie-api")
public interface MovieApi {
@RequestMapping(method = RequestMethod.GET, value = "/movies/{id}")
Movie getMovie(@PathVariable("id") Long id);
}