From 7375c9d10666b2e8b840cdd4708ac51862caa06f Mon Sep 17 00:00:00 2001 From: itsme-shawn Date: Wed, 31 Jan 2024 06:55:35 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20NoResourceFoundException=20=EB=B0=9C?= =?UTF-8?q?=EC=83=9D=ED=95=A0=20=EB=95=8C=20=EB=A1=9C=EA=B7=B8=20=EC=95=88?= =?UTF-8?q?=20=EB=9C=A8=EB=8F=84=EB=A1=9D=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 글로벌 exception 수정 - 수동배포 파일 생성 - 시큐리티 설정 수정 --- deploy_prod.sh | 9 +++++++++ .../example/reddiserver/common/ApiExceptionHandler.java | 8 +++++++- .../example/reddiserver/config/WebSecurityConfig.java | 6 +++--- 3 files changed, 19 insertions(+), 4 deletions(-) create mode 100644 deploy_prod.sh diff --git a/deploy_prod.sh b/deploy_prod.sh new file mode 100644 index 0000000..a496ddd --- /dev/null +++ b/deploy_prod.sh @@ -0,0 +1,9 @@ +./gradlew bootJar + +aws ecr get-login-password --region ap-northeast-2 | docker login --username AWS --password-stdin 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com + +docker build --platform amd64 -t reddi-server . + +docker tag reddi-server:latest 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest + +docker push 533267191976.dkr.ecr.ap-northeast-2.amazonaws.com/reddi-server:latest \ No newline at end of file diff --git a/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java b/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java index 3571d40..cb83868 100644 --- a/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java +++ b/src/main/java/com/example/reddiserver/common/ApiExceptionHandler.java @@ -5,13 +5,19 @@ import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.servlet.resource.NoResourceFoundException; @Slf4j @RestControllerAdvice public class ApiExceptionHandler { + @ExceptionHandler(NoResourceFoundException.class) + public ResponseEntity> handleNoResourceFoundException(NoResourceFoundException exception) { + // NoResourceFoundException이 발생했을 때 아무런 처리도 하지 않음 + return ResponseEntity.ok().build(); + } + @ExceptionHandler(Exception.class) public ResponseEntity> handleExceptions(Exception exception) { - log.error("Exception occurred:", exception); // 스택 트레이스 정보를 포함한 로깅 return ResponseEntity.status(HttpStatus.BAD_REQUEST).body(ApiResponse.errorResponse(exception.getMessage())); diff --git a/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java b/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java index d2d1149..82e15fe 100644 --- a/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java +++ b/src/main/java/com/example/reddiserver/config/WebSecurityConfig.java @@ -28,10 +28,10 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .csrf(csrf -> csrf.disable()) .sessionManagement(sessionManagement -> sessionManagement.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) - .httpBasic(httpBasic -> httpBasic.disable()) - .formLogin(formLogin -> formLogin.disable()) +// .httpBasic(httpBasic -> httpBasic.disable()) +// .formLogin(formLogin -> formLogin.disable()) .authorizeHttpRequests((authorize) -> authorize - .requestMatchers("/static/**", "/resources/**", "/css/**", "/js/**", "/images/**", "/**", "/swagger-ui/**", "/v3/api-docs/**").permitAll() + .requestMatchers("/static/**", "/resources/**", "/css/**", "/js/**", "/images/**").authenticated() .requestMatchers(HttpMethod.GET, "/**").permitAll() .requestMatchers(HttpMethod.GET, "/swagger-ui/**").permitAll() .requestMatchers(HttpMethod.GET, "/v3/api-docs/**").permitAll()