RestTemplate 종속성이있는 클래스가 있습니다.
@Service
public class SwiftAPIPushHandler {
private final ObjectMapper objectMapper;
private final RestTemplate restTemplate;
@Value("${app.swift.host}")
private String swiftHost;
@Value("${app.swift.client.secret}")
private String clientSecret;
public SwiftAPIPushHandler(@Autowired RestTemplate restTemplate,
@Autowired ObjectMapper objectMapper) {
this.restTemplate = restTemplate;
this.objectMapper = objectMapper;
}
@ServiceActivator
public Map<String, Object> outboundSwiftPushHandler(Map<String, Object> payload,
@Header("X-UPSTREAM-WEBHOOK-SOURCE") String projectId) throws JsonProcessingException {
// HTTP POST Request from RestTemplate here
}
}
그리고 테스트 @RestClientTest
에서 자동 구성 에 사용 하고 싶습니다 .RestTemplate
@RestClientTest
@SpringJUnitConfig(classes = {SwiftAPIPushHandler.class})
public class SwiftAPIPushHandlerTest {
@Autowired
SwiftAPIPushHandler apiPushHandler;
@Test
public void testSwiftApiPush(
@Value("classpath:sk-payloads/success-response.json") Resource skPayload) throws IOException {
// blah blah blah
}
}
그러나 RestTemplate 오류에 대한 자동 연결 후보를 찾을 수 없어 테스트가 실패합니다.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 0 of constructor in com.swift.cloud.transformation.engine.SwiftAPIPushHandler required a bean of type 'org.springframework.web.client.RestTemplate' that could not be found.
The injection point has the following annotations:
- @org.springframework.beans.factory.annotation.Autowired(required=true)
Action:
Consider defining a bean of type 'org.springframework.web.client.RestTemplate' in your configuration.