본문 바로가기

spring util5

@RestControllerAdvice - 전역 예외 처리 @RestControllerAdvice를 사용해 모든 Controller에 대한 예외 처리를 한 곳에서 관리 및 처리*공통 에러 메시지 및 이외 예외들을 공통 처리 하는 예제*자세한 설명 생략  ▷ @RestControllerAdvice란?     - Application 전역 예외 처리 Annotation      - Project 하나의 @ControllerAdvice만 관리하는 것을 권장      - @Controller Annotation이 붙은 Controller에서 발생하는 예외를 처리      - @ResponseBody가 있어 JSON 응답          *@ControllerAdvice 차이      - @ExceptionHandler를 통해 처리          *Method 범위 E.. 2023. 11. 17.
SpringBoot Security Login 기능 추가 아주 간단한 Spring Security Login 기능 추가 방법*Maven 사용*Spring Boot Project 생성 과정 생략*자세한 설명 생략  ▷ pom.xml*의존성 추가  org.springframework.boot spring-boot-starter-security  ▷ application.properties*사용자 지정 ID/PWD 설정* Default user ID : user * Default user Pwd : 서버 실행 시 제공( Using generated security password: fd67f8d9-652b-46cd-a147-4b6681292d50 ) spring.security.user.name = testspring.security.user.passwo.. 2023. 9. 26.
@Value 사용법 application.properties에 설정한 값을 가져와 사용하는 @Value*자세한 설명 생략  ▷ application.properties*Test를 위한 값 설정 # valuetest.val = HELLO# maptest.mapInt = {W:0, O:1, R:2, L:3, D:4}test.mapStr = {W:'w', O:'o', R:'r', L:'l', D:'d'}# listtest.listInt = 0, 1, 2, 3, 4test.listStr = H, E, L, L, O  ▷ Application.java*간단한 Test를 위해 Application.java에서 진행*Bean이 생성된 후 사용해야 하기 때문에 CommandLineRunner 사용*CommandLineRunner : Se.. 2023. 9. 21.
Custom Annotation 생성 Example 간단한 Custom Annotation 생성, 확인*메타 어노테이션 관련 자세한 설명 생략*Reflection 설명 생략  import java.lang.annotation.ElementType;import java.lang.annotation.Retention;import java.lang.annotation.RetentionPolicy;import java.lang.annotation.Target;/** * 사용자 정의 어노테이션 생성 */@Target(ElementType.TYPE) // @interface 어노테이션의 적용 위치를 설정하는 옵션@Retention(RetentionPolicy.RUNTIME) // @interface 어노테이션의 적용범위로 어떤 시점까지 사용될 지 결정하는 옵션@in.. 2023. 7. 26.
@EventListener Example ▷ Example-  Application Context 초기화 및 수정 시 파일을 읽어 오는 예제 @Componentpublic class TestGetName { @Getter @Setter private String USER_NAME = ""; // 애플리케이션 시작을 감지 // @EventListener : 이벤트가 발생했을때 이벤트를 수신해서 처리 // ContextRefreshedEvent : Application Context를 초기화 했거나 수정했을때 발생 @EventListener public void onApplicationEvent(ContextRefreshedEvent event) { try{ // 파일 .. 2021. 5. 18.
728x90
728x90