2024-07-17T16:37:31.387+09:00 ERROR 18908 --- [nio-8080-exec-1] c.d.s.global.exeption.ExceptionAdvice : RuntimeException : Cannot invoke "com.donghaha.server.villager.model.service.VillagerService.readVillagerList(com.donghaha.server.villager.model.dto.ReadVillagerListCommandDto)" because "this.villagerService" is null
토이 프로젝트 개발 중 위와 같은 오류를 만나게 되었다.
위와 같은 에러는 처음 만나게 되어 당황스러웠는데, 이유는 간단했다.
@RestController
@RequestMapping("villager")
@RequiredArgsConstructor
public class VillagerController {
//VillagerService villagerService; //수정 전
private final VillagerService villagerService; //수정 후
}
이유는 Auto Required 되는 컴포넌트에 final
을 붙이지 않아서...
final
로 상수 선언을 하지 않으면 Bean 주입이 되지 않아 null 값이 된다고 한다.
'프레임워크 및 라이브러리 > Spring' 카테고리의 다른 글
[Spring Boot] MyBatis Bean 주입 오류 available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {} (2) | 2024.10.12 |
---|---|
[MyBatis] MyBatis 초기 설정하기 (2) | 2024.07.08 |
[MyBatis] argument type mismatch (0) | 2024.07.01 |
RestClient 자동 인코딩 (공공데이터 API Key Error) (0) | 2024.04.12 |
WebClient를 사용하지 않게 된 이유, 그리고 RestClient (1) | 2024.03.27 |