개발새발

[Spring] parameter 1 of constructor in required a bean of type 'org.springframework.security.crypto.password.passwordencoder' that could not be found. 본문

오류잡기

[Spring] parameter 1 of constructor in required a bean of type 'org.springframework.security.crypto.password.passwordencoder' that could not be found.

칸쵸. 2024. 1. 25. 17:23
728x90

 

회원가입 기능을 구현하려는 중...

보안을 위해 Spring security에서 제공하는 기능 주 중 하나인 PasswordEncoder를 사용하고자했다.

 

import org.springframework.security.crypto.password.PasswordEncoder;

분명 import까지 야무지게 해왔는데

 

***************************

APPLICATION FAILED TO START

***************************

 

Description:

 

Parameter 1 of constructor in com.penpick.users.service.UserService required a bean of type 'org.springframework.security.crypto.password.PasswordEncoder' that could not be found.

 

음...

passwordEncoder가 bean으로 등록되지 않아서 생기는 문제같다.

 

고민 좀 하다가 SecurityConfig 파일에 들어가서 @Bean 설정한 메서드를 하나 추가해줌

 

@Bean

public PasswordEncoder passwordEncoder() {

PasswordEncoder encoder = new BCryptPasswordEncoder();

return encoder;

}

 

BCryptPasswordEncoder 를 Super Class로 하도록 설정

 

그리고 다시 실행

 

DB 저장. 성공적.