-1

I am trying to get data from external service and put the in database.

@FeignClient(value = "name-feign", url = "http://localhost:8081")
public interface Client{

    @PostMapping("/Efforts")
    List<EffortsResponse> getAllEfforts();

}

I added @EnableFeignClients annotation on my app. I know what feign client do.

what is the best way to do it?

1 Answers1

2

You can inject the feign client and repository into the service.

There should have a method in the service like this:

@Service
public class Service {
  private final Client client;
  private final Repository repository;

  public Service(Client c, Repository r) {
    this.client = c;
    this.repository = r;
  }

  public yourMethod() {
    List<EffortsResponse> items = client.getAllEfforts();
    //some transformation: items => entities
    respository.saveAll(entities);
  }
}
Max Peng
  • 2,879
  • 1
  • 26
  • 43