모두 생성자를 자동 생성하는 어노테이션으로 생성방식에 약간의 차이가 있다.
필드 없는 생성자 생성
@NoArgsConstructor
public class user{
int id;
String email;
String password;
}
annotation 작동 결과:
public user(){};
모든 필드를 매개변수로 받는 생성자 생성
예시)
@AllArgsCounstructor
public class user{
int id;
String email;
String password;
}
annotation 작동 결과:
public user(int id, String email, String password){
this.id=id;
this.email=email;
this.password=password;
};
final
, @notNull
붙은 변수에만 생성자 주입
@RequiredArgsConstructor
public class user{
private final UserRepository;
String nickname;
}
annotation 작동 결과:
public user(UserRepository userRepository, String nickname){
this.userRepository=userRepository;
this.nickname=nickname;
}
No - x,
All- 모두,
Required- final, @notNull 주로 의존성 주입에 쓰임