반응형
에러 내용
문제는 WeatherService 클래스에서 RestTemplate 빈을 찾을 수 없다는 것입니다. 스프링 부트 애플리케이션에서 RestTemplate를 사용하려면 빈으로 등록해야 합니다.
Description:
Field restTemplate in com.pj.web.service.WeatherService 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)
해결 방법
AppConfig 클래스를 생성해서 bean으로 등록해준다. 그 후 서비스에서 autowired로 불러와서 사용 가능.
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;
@Configuration
public class AppConfig {
@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
}
}
반응형
'프로그래밍' 카테고리의 다른 글
[Spring] sts4 사용 중 resources 폴더가 없어졌을 때 (0) | 2024.07.01 |
---|---|
[GitHub] rejected non-fast-forward 에러 간단 해결 방법 (0) | 2024.06.27 |
[MariaDB] application.properties 설정 MariaDBDialect (0) | 2024.06.19 |
[캡쳐] 한 페이지 전부 스크롤 캡쳐하는 방법 (0) | 2024.06.15 |
Node.js, React 초기 세팅 (0) | 2024.06.10 |
댓글