Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[오류] p.150 IndexController에서 NullPointerException이 뜹니다... #258

Closed
lee-garden opened this issue Feb 15, 2020 · 2 comments
Closed

Comments

@lee-garden
Copy link

기존에 올라온 질문이 아닌지 먼저 검색해주세요!

가장 자주 나온 제보

어떤 오류인가요?

오류설명: 150p까지 실습을 진행 하고 있습니다.
Post insert 하고 index 페이지에서 PostList를 불러 오려는데 IndexController에서 NullPointerException이 뜹니다... h2-console에서 아이템 잘 들어가 있는거 확인했는데 왜 그런지 이유를 못찾겠습니다.

프로젝트 주소

Github에 오류가 난 프로젝트를 올려주세요.
Github 주소를 작성해주지 않으시면 답변해드릴수가 없어요!

오류 로그

image

어떤 오류인지 캡쳐해주세요.

@MinhoLee93
Copy link

@97e57e

IndexController 상단에 @requiredargsconstructor 선언을 빼놓으셨어요!
데이터가 문제가 아니라, PostService가 null 이라서 NullPointerException 가 발생하신거에요.

또한 @requiredargsconstructor를 사용해 생성자 주입으로 의존성을 주입 받기 위해선
private final로 변수를 선언해야 합니다.

기존 : private PostsService postService
변경 : private final PostsService postService + @requiredargsconstructor 선언

위와 같이 변경후 정상작동 확인했습니다 :)

@lee-garden
Copy link
Author

@MinhoLee93 아 .. 감사합니다.. 몇번 확인한다고 했는데도 빼먹은 부분이 있었네요 ㅠ :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants