Home

0

Java - Collection Framework

Java - Collection FrameworkStack 먼저 들어간 데이터가 가장 마지막에 나오는 구조 (First In First Out) 메서드 설명 void push(E e) stack 최상단에 데이터를 추가한다. Element pop() stack 최상단 데이터를 반환한 후 스택 최상단 데이터를 삭제한다. Element peek() stack 최상단 데이터를 반환한다. boolean isEmpty() stack 이 비어있는지 확인한다. int size() stack 의 크기를 반환한다. Queue 메서드 설명 boolean add(E e) Queue 맨 뒤에 데이터를 추가한 후 정상적으로 수행했으면 True, 데이터 삽입에 실패하면 False 를 반환한다. Queue 에 여유 공간이 없어 실패한 경우 IllegalStateException 예외를 발생 시킨다. boolean offer(E e) Queue 맨 뒤에 데이터를 추가한 후 정상적으로 수행했으면 True, 데이터 삽입에 실패하면 False 를 반환한다. E element() Queue 맨 앞의 원소를 반환한다. E peek( ) Queue 맨 앞의 원소를 반환한다. Queue 가 비어있을 경우 null 을 반환한다. E poll( ) Queue 맨 앞의 원소를 반환한 후 삭제한다. Queue 가 비어있을 경우 null 을 반환한다. E remove() Queue 맨 앞의 원소를 삭제한다.

0

[Spring AOP] - Advice 종류

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 Spring 핵심원리 고급편 - 어드바이스 종류 종류 설명 @Around 메서드 호출 전 후에 실행, 가장 강력한 어드바이스, 조인 포인트 실행 여부 선택, 반환 값 변환, 예외 변환 등이 가능 @Before 조인 포인트 실행 이전에 실행 @AfterReturning 조인 포인트가 정상 완료 후 실행 @AftThrowing 메서드가 예외를 던지는 경우 실행 @After 조인 포인트가 정상 또는 예외에 관계 없이 실행 @Slf4j@Aspectpublic class AspectV6Advice { // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ // @Before log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); // @AfterReturning log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ // @AfterThrowing log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { // @After log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }} @Slf4j@Aspectpublic class AspectV6Advice { // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ // @Before log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); // @AfterReturning log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ // @AfterThrowing log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { // @After log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } } // @Before 은 그냥 실행해준다. @Before("com.example.aop.order.aop.Pointcuts.orderAndService()") public void doBefore(JoinPoint joinPoint){ log.info("[before] {}", joinPoint.getSignature()); } // return 값을 조작을 할 수는 있지만 바꿀 수 는 없다. @AfterReturning(value = "com.example.aop.order.aop.Pointcuts.orderAndService()", returning = "result") public void doReturn(JoinPoint joinPoint, Object result){ log.info("[return] {} return = {}", joinPoint.getSignature(), result); } // 자동으로 throw ex 를 해준다. @AfterThrowing(value = "com.example.aop.order.aop.Pointcuts.orderAndService()", throwing = "ex") public void doThrowing(JoinPoint joinPoint, Exception ex){ log.info("[ex] {} message = {}", ex); } @After(value = "com.example.aop.order.aop.Pointcuts.orderAndService()") public void doAfter(JoinPoint joinPoint){ log.info("[after] {}", joinPoint.getSignature()); }} 모든 어드바이스는 JoinPoint 를 첫번째 파라미터에 사용할 수 있다. 단 @Around 는 ProceedingJoinPoint 를 사용해야 한다.ProceedingJoinPoint는 JoinPoint 의 하위 타입니다. JoinPoint 인터페이스의 주요 기능 Method 설명 getArgs 메서드 인수를 반환한다. getThis 프록시 객체를 반환한다. getTarget 대상 객체를 반환한다. getSignature 조언되는 메서드에 대한 설명을 반환한다. toString 조언되는 방법에 대한 유용한 설명을 인쇄한다.

0

[Spring AOP] - 트랜잭션 순서

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 Spring 핵심원리 고급편 - 트랜잭션 순서@Slf4jpublic class AspectV5Order { @Aspect @Order(2) public static class LogAspect{ @Around("com.example.aop.order.aop.Pointcuts.allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } } @Aspect @Order(1) public static class TxAspect{ // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } } }}

0

[Spring AOP] - 포인트컷 참조

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 Pointcutpublic class Pointcuts { @Pointcut("execution(* com.example.aop.order..*(..))") public void allOrder(){} // 클래스 이름 패턴이 *Service @Pointcut("execution(* *..*Service.*(..))") public void allService(){} // allOrder && allService @Pointcut("allOrder() && allService()") public void orderAndService(){}} 외부 Pointcut 참조@Slf4j@Aspectpublic class AspectV4PointCut { @Around("com.example.aop.order.aop.Pointcuts.allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("com.example.aop.order.aop.Pointcuts.orderAndService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }} @Slf4j@SpringBootTest@Import(AspectV4PointCut.class)public class AopTest { @Autowired OrderService orderService; @Autowired OrderRepository orderRepository; @Test public void aopTest(){ log.info("isAopProxy, orderService = {}", AopUtils.isAopProxy(orderService)); log.info("isAopProxy, orderRepository = {}", AopUtils.isAopProxy(orderRepository)); } @Test public void success(){ orderService.orderItem("itemA"); } @Test public void exception(){ assertThatThrownBy(() -> orderService.orderItem("ex")) .isInstanceOf(IllegalStateException.class); }}

0

[Spring AOP] - 어드바이스 추가

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 Advice 추가 기존에 로그를 찍은 기능에서 트랜잭션 기능 추가 allOrder com.example.aop.order 하위 패키지를 대상으로 포인트 컷 적용 allService 타입 이름 패턴이 *Service 를 대상으로 포인트 컷 적용 타입 이름 패턴 : 클래스, 인터페이스 모두 적용 @Around(“allOrder() && allService()”) 포인트 컷은 조합이 가능하다 && : AND || : OR ! : NOT @Slf4j@Aspectpublic class AspectV3 { @Pointcut("execution(* com.example.aop.order..*(..))") private void allOrder(){} // 클래스 이름 패턴이 *Service @Pointcut("execution(* *..*Service.*(..))") private void allService(){} @Around("allOrder()") public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); } // com.example.aop.order 하위 패키지면서 클래스 이름 패턴이 *Service 인 것 @Around("allOrder() && allService()") public Object doTransaction(ProceedingJoinPoint joinPoint) throws Throwable{ try{ log.info("[트랜잭션 시작] {}", joinPoint.getSignature()); Object result = joinPoint.proceed(); log.info("[트랜잭션 커밋] {}", joinPoint.getSignature()); return result; }catch (Exception ex){ log.info("[트랜잭션 롤백] {}", joinPoint.getSignature()); throw ex; }finally { log.info("[리소스 릴리즈] {}", joinPoint.getSignature()); } }}

0

[Spring AOP] - @Pointcut 포인트컷 분리

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 ✅ Spring AOP - 포인트컷 분리 하나의 Pointcut 표현식을 여러 어드바이스에서 함께 사용하는 것이 가능하다. 스프링 AOP 에서는 Advice 를 적용하기 위한 포인트컷을 별로로 분리해 생성할 수 있습니다. 덕분에 같은 로직을 여러번 작성해야 하는 코드의 중복을 방지해 코드의 재사용성과 유지보수성을 향상시킬 수 있습니다. 포인트컷은 크게 두가지 구성요소로 이루어집니다. 첫번째는 어디에 Advice 를 적용할지 정의하는 포인트컷 표현식 과 두번째는 포인트컷을 정의하는 메서드의 이름과 매개변수를 의미하는 포인트컷 시그니처 로 이루어져 있습니다. ✅ @Pointcut - 포인트컷 생성하기포인트컷을 별도로 생성하기 위해서는 @Pointcut 을 사용하여 포인트컷 표현식을 메서드로 정의합니다. 이때, 메서드의 반환 타입은 void 여야 하고 코드 내용은 비어있어야 합니다. @Pointcut 이 붙은 메서드를 Advice 가 참조하면 포인트컷 표현식에 따라 부가기능 적용 여부를 판단하게 됩니다. AspectV2@Slf4j@Aspectpublic class AspectV2 { @Pointcut("execution(* com.example.aop.order..*(..))") private void allOrder(){ } @Around("allOrder()") // 포인트컷 표현식이 작성된 포인트컷 시그니처를 지정합니다. public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable{ log.info("[log] {}", joinPoint.getSignature()); // join point 시그니처 return joinPoint.proceed(); }}

0

[Spring AOP] - @Aspect

목차 [Spring AOP] - Advice 종류 [Spring AOP] - 트랜잭션 순서 [Spring AOP] - 포인트컷 참조 [Spring AOP] - 어드바이스 추가 [Spring AOP] - @Pointcut 포인트컷 분리 [Spring AOP] - @Aspect [Spring AOP] - Aspect [Spring AOP] - 용어 정리 [Spring AOP] - 적용 방식 ✅ @Aspect 작동방식스프링 애플리케이션은 로딩 시점에 자동 프록시 생성기 를 호출되며 스프링 컨테이너에서 @Aspect 가 붙은 Bean 들을 검색합니다. 검색된 각 @Aspect 빈에 대해, @Aspect 어드바이저 빌더를 사용하여 어드바이저를 생성합니다. 생성된 어드바이저는 @Aspect 어드바이저 빌더 내부에 저장됩니다. 1. 자동 프록시 생성기 역할 - @Aspect 어드바이저 생성@Aspect 가 적용된 Bean 들을 조회합니다. 해당 Bean 내 정의된 Advice 와 Pointcut 표현식을 이용해 Advisor 를 생성 후 저장합니다. 2. 자동 프록시 생성기 역할 - @Aspect 어드바이저 적용Bean 객체 생성시 Bean 후처리기에서 Advisor 객체를 조회해 Pointcut 표현식에 해당되는 Bean 이 있을 경우 자동 프록시 생성기에서 Advice(부가기능) 가 적용된 프록시 객체를 생성합니다.

0

Redux 사용하기 - 계산기 만들기

목차 Redux Saga Redux Middleware 만들기 Redux 사용하기 - 계산기 만들기 Redux 사용하기 라이브러리 설치 yarn add react-redux Action Type 정의/* 액션 타입 만들기 */// Ducks 패턴을 따를땐 액션의 이름에 접두사를 넣어주세요.// 이렇게 하면 다른 모듈과 액션 이름이 중복되는 것을 방지 할 수 있습니다.const SET_DIFF = "counter/SET_DIFF";const INCREASE = "counter/INCREASE";const DECREASE = "counter/DECREASE"; Action 생성 함수/* 액션 생성함수 만들기 */// 액션 생성함수를 만들고 export 키워드를 사용해서 내보내주세요.export const setDiff = (diff) => ({ type: SET_DIFF, diff });export const increase = () => ({ type: INCREASE });export const decrease = () => ({ type: DECREASE }); Reducer

0

Redux 사용하기 - 계산기 만들기

목차 Redux Saga Redux Middleware 만들기 Redux 사용하기 - 계산기 만들기 Redux 사용하기 라이브러리 설치Action 정의하기export const INCREASE = "counter/INCREASE" as const;export const DECREASE = "counter/DECREASE" as const;interface increaseAction { type: typeof INCREASE;}interface decreaseAction { type: typeof DECREASE;}export type CounterType = increaseAction | decreaseAction; Action 생성 함수export const increase = (): increaseAction => ({ type: INCREASE,});export const decrease = (): decreaseAction => ({ type: DECREASE,}); Stateinterface CounterState { value: number;}const initialState: CounterState = { value: 0,};

0

Redux 사용하기

목차 Redux Saga Redux Middleware 만들기 Redux 사용하기 - 계산기 만들기 Redux 사용하기 Redux 사용하기 하나의 애플리케이션 안에는 하나의 Store 가 존재 State 는 읽기 전용 불변성 을 지켜줘야 한다. 객체의 경우 Spread 연산자 를 사용해 기존 객체를 덮어써준다. 배열의 불변성을 지켜주는 내장함수를 사용해야 한다. 불변성을 지켜야만 Component 들이 제대로 Rerendering 된다. 변화를 일으키는 함수, Reducer 는 순수한 함수 여야 한다. Reducer 는 이전 상태 와 Action 객체 를 파라미터로 받는다. 이전 상태를 변경하지 않고 새로운 상태를 만들어 반환한다.(불변성 유지) 똑같은 파라미터로 호출된 리듀서는 언제나 똑같은 결과값을 반환해야 한다. Redux 모듈 설치yarn add react-redux Action 상태의 변화가 필요할 경우 Action 을 일으킨다.