configuration.EncryptionConfig.java
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
@Configuration
public class EncryptionConfig {
@Bean
public PasswordEncoder encoder(){
return PasswordEncoderFactories.createDelegatingPasswordEncoder();
}
}
프로젝트 내에서 전 범위적으로 사용되기 때문에 bean으로 등록해야 사용할 수 있음
@Configuration을 따로 만든 이유는 CGLib으로 프록시 패턴을 적용해 수동으로 등록하는 스프링 빈이 반드시 싱글톤으로 생성됨을 보장하기 위해서이다.
@bean이 있는 메소드를 여러 번 호출하여도 항상 동일한 객체를 반환하여 싱글톤을 보장한다.