[Spring 프로젝트][에러] Null point Exption

heyhey·2023년 3월 21일
0

프로젝트

목록 보기
2/8

NullpointException

Servlet.service() for servlet [dispatcherServlet] in
context with path [] threw exception [Request
processing failed; nested exception is 
java.lang.NullPointerException] with root cause

원인은 Query에 Null 값이 들어갔을 경우 발생하는 문제라고 한다.

코드부터 다시 보도록 하자
userController.java

@GetMapping("/all")
public ResponseEntity<?> getAllUsers() {
   return new ResponseEntity<>(userService.getAllUsers(), HttpStatus.OK);
}

userService.getAllUsers() 이 값이 없다는 것일 가능성이 높다.

먼저 userService의 주입 방식을 확인한다.

Spring 에서 @Autowired 어노테이션을 사용하여 의존성 주입이 된 상태인지를 확인해야 한다.

엇.. 빠뜨렸었다.

@Autowired
private UserService userService;

완료.

아직 스프링에 대한 이해도가 부족한 것 같다. 오류를 조금씩 만나가면서 이해하도록 하겠다

profile
주경야독

0개의 댓글