Error
- rest template을 다음과 같이 사용했을 때 Error가 발생했다.
- service 인터페이스
package kr.pe.playdata.service;
import java.util.concurrent.CompletableFuture;
public interface RecommandService {
public CompletableFuture<String> recommand(String keywords);
}
- service 구현
package kr.pe.playdata.service.impl;
import kr.pe.playdata.service.RecommandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.concurrent.CompletableFuture;
@Service
public class RecommandServiceImpl implements RecommandService {
@Autowired
private RestTemplate restTemplate;
@Bean
public RestTemplate restTemplate(){
return new RestTemplate();
}
@Async("asyncExecutor")
public CompletableFuture<String> recommand(String keywords){
String url = "http://127.0.0.1:5000/recommand";
MultiValueMap<String, String> param = new LinkedMultiValueMap<String, String>();
param.add("keywords",keywords);
String sb = restTemplate.postForObject(url, param, String.class);
return CompletableFuture.completedFuture(sb);
}
}
- Error 발생
Error 해결
참고 사이트
Circular Dependency in Spring Boot