From cd798e27a9063e4766b601deebb776aa1232da26 Mon Sep 17 00:00:00 2001 From: parkduhwan Date: Thu, 8 Aug 2024 21:56:57 +0900 Subject: [PATCH] =?UTF-8?q?=EC=88=9C=ED=99=98=20=EC=9D=98=EC=A1=B4?= =?UTF-8?q?=EC=84=B1=20=EC=98=A4=EB=A5=98=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit JWT,시큐리티,userService 파일이 서로를 의존하고 있어 순환 의존성을 끊어 문제를 해결함 --- .../config/PasswordEncoderConfig.java | 16 ++++++++++++++++ .../healthylife/config/SecurityConfig.java | 6 ------ .../example/healthylife/service/UserService.java | 1 + 3 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/main/java/com/example/healthylife/config/PasswordEncoderConfig.java diff --git a/src/main/java/com/example/healthylife/config/PasswordEncoderConfig.java b/src/main/java/com/example/healthylife/config/PasswordEncoderConfig.java new file mode 100644 index 0000000..6006804 --- /dev/null +++ b/src/main/java/com/example/healthylife/config/PasswordEncoderConfig.java @@ -0,0 +1,16 @@ +package com.example.healthylife.config; + +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; +import org.springframework.security.crypto.password.PasswordEncoder; +@Configuration +public class PasswordEncoderConfig { + + //비밀번호 암호화 작업 + @Bean + public PasswordEncoder passwordEncoder() { + return new BCryptPasswordEncoder(); + } +} + diff --git a/src/main/java/com/example/healthylife/config/SecurityConfig.java b/src/main/java/com/example/healthylife/config/SecurityConfig.java index 8e19887..58440a7 100644 --- a/src/main/java/com/example/healthylife/config/SecurityConfig.java +++ b/src/main/java/com/example/healthylife/config/SecurityConfig.java @@ -28,12 +28,6 @@ protected void configure(HttpSecurity http) throws Exception { .addFilterBefore(new JwtAuthenticationFilter(jwtUtil), UsernamePasswordAuthenticationFilter.class); } - //비밀번호 암호화 작업 - @Bean - public PasswordEncoder passwordEncoder() { - return new BCryptPasswordEncoder(); - } - //AuthenticationManager를 빈으로 등록하게 해서 시큐리티가 인증 매니저를 할수 있게 한다. @Bean @Override diff --git a/src/main/java/com/example/healthylife/service/UserService.java b/src/main/java/com/example/healthylife/service/UserService.java index 51e4442..ea36f8c 100644 --- a/src/main/java/com/example/healthylife/service/UserService.java +++ b/src/main/java/com/example/healthylife/service/UserService.java @@ -4,6 +4,7 @@ import com.example.healthylife.repository.UserRepository; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.springframework.context.annotation.Lazy; import org.springframework.security.crypto.password.PasswordEncoder; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional;