27 Eylül 2021 Pazartesi

SpringCloud Feign Client @EnableFeignClients Anotasyonu

Giriş
Şu satırı dahil ederiz
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.feign.EnableFeignClients;
Bu anotasyon @FeignClient anotasyonlarının taranması için gereklidir.

Örnek
Şöyle yaparız
@EnableDiscoveryClient
@EnableFeignClients
@SpringBootApplication
public class EmployeeDashBoardServiceApplication {

  public static void main(String[] args) {
    SpringApplication.run(EmployeeDashBoardServiceApplication.class, args);
 

  @Bean
  public RestTemplate restTemplate(RestTemplateBuilder builder) {
    return builder.build();
  }
}
basePackages Alanı 
Örnek
Şöyle yaparız
@SpringBootApplication
@EnableFeignClients("io.xrio.movies.controller.client")
public class MoviesApplication {
  ...
}
clients Alanı
Örnek
Şöyle yaparız
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;

import cz.zpapez.springfeignclients.slack.SlackFeignClient;
import cz.zpapez.springfeignclients.zephyr.ZephyrFeignClient;

@SpringBootApplication
@EnableFeignClients(clients = {
        SlackFeignClient.class,
        ZephyrFeignClient.class
})
public class SpringFeignClientsApplication {

  public static void main(String[] args) {
    SpringApplication.run(SpringFeignClientsApplication.class, args);
  }

}

Hiç yorum yok:

Yorum Gönder