기술해록본

java.lang.IllegalArgumentException: rawPassword cannot be null 본문

Develop/To All The Errors I've Loved Before

java.lang.IllegalArgumentException: rawPassword cannot be null

HaeYoung_12 2024. 10. 6. 15:00
java.lang.IllegalArgumentException: rawPassword cannot be null
at org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder.encode

 

 

- 처음에는 BCryptPasswordEncoder 관련 @Autowired 문제라고 생각 했으나 블로그를 참고해보니

JSON BODY로 보내면 controller 에서 받을 때 인지를 할수 있게 @RequestBody  어노테이션을 작성했어야 하는데 붙이지 않아서 발생한 문제이다.

 

- 여기서

private static final Logger log = LoggerFactory.getLogger(userController.class);
    @Autowired
    private UserService service;
    @PostMapping("/signup")
    public ResponseEntity<?> SignUp(@Validated  AddUserRequest addUserRequest, BindingResult result) {

        if(result.hasErrors()) {
            log.warn(result.toString());
            return ResponseEntity.badRequest().body(result.getFieldError());
        }
        try {

            Boolean flag=service.singUp(addUserRequest);
            return ResponseEntity.ok().body(flag);

 

- 이렇게 수정했더니 해결

private static final Logger log = LoggerFactory.getLogger(userController.class);
    @Autowired
    private UserService service;
    @PostMapping("/signup")
    public ResponseEntity<?> SignUp(@RequestBody @Validated  AddUserRequest addUserRequest, BindingResult result) {

        if(result.hasErrors()) {
            log.warn(result.toString());
            return ResponseEntity.badRequest().body(result.getFieldError());
        }
        try {

            Boolean flag=service.singUp(addUserRequest);
            return ResponseEntity.ok().body(flag);

 

 

- 참고자료

https://grogrammer.tistory.com/42

 

[개발]🚨ERROR - java.lang.IllegalArgumentException: rawPassword cannot be null

🛤️상황 회원가입/로그인이 기존에 GET방식이었어서 POST 방식으로 바꾸려 하는데 이러한 오류가 발생하였다. 🌸과정 401 Unauthorized는 클라이언트 요청이 필요한 인증 자격증명을 제공하지 않았

grogrammer.tistory.com