Springboot 이게 왜이렇게 동작하는걸까

Sorbet·2021년 3월 9일
0

스프링부트에서 게시판 기능 구현을 하다가

  • domain에 User 클래스에
    • 아래같은 코드로 회원가입 기능을 굴리면 정상동작 하는데
package com.codessquad.qna.domain;

public class User {

    private String userId;
    private String password;
    private String name;
    private String email;


    @Override
    public String toString() {
    //투스트링 메서드 생략
    }
    
    //게터세터 생략

}

근데 이상하게 도메인에 코드를 추가하면 컨트롤러를 못찾는다

  • 이렇게 뭔가 나만의 copyConstructor 를 만드니까 동작을 안한다.
package com.codessquad.qna.domain;

public class User {

    private String userId;
    private String password;
    private String name;
    private String email;

    public User(User copyUser) {
        this.userId = copyUser.userId;
        this.password = copyUser.password;
        this.name = copyUser.name;
        this.email = copyUser.email;
    }

    @Override
    public String toString() {
    //투스트링 메서드 생략
    }
    
    //게터세터 생략

}

콘트롤러는 이런데

 @PostMapping("/usercreate")
    public String create(User user) {
        userList.add(user);

        return "redirect:/users/list";
    }

여기서 질문, 왜 domain에 생성자 하나 추가했다고, 자바스프링이 아래와 같은 에러메시지를 보내줄까 궁금합니다..

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Tue Mar 09 12:39:13 KST 2021
There was an unexpected error (type=Internal Server Error, status=500).
Failed to instantiate [com.codessquad.qna.domain.User]: Constructor threw exception; nested exception is java.lang.NullPointerException
org.springframework.beans.BeanInstantiationException: Failed to instantiate [com.codessquad.qna.domain.User]: Constructor threw exception; nested exception is java.lang.NullPointerException
profile
Sorbet is good...!

0개의 댓글