Notice
Recent Posts
Recent Comments
Link
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Archives
Today
Total
관리 메뉴

개발자되기 프로젝트

[스프링AOP 포인트컷] bean 본문

인프런/[인프런] 스프링 핵심 원리 - 고급

[스프링AOP 포인트컷] bean

Seung__ 2022. 1. 7. 22:38

1. bean


  • 스프링 전용 포인트컷 지시자, 빈의 이름으로 지정한다
  • 스프링 빈의 이름으로 AOP 적용 여부를 지정한다. 
  • bean(orderService) || bean(*Repository)
  • * 과 같은 패턴을 사용할 수 있다.

 

2. Test


@Slf4j
@Service
public class OrderService {
    private final OrderRepository orderRepository;
    public OrderService(OrderRepository orderRepository) {
        this.orderRepository = orderRepository;
    }
    public void orderItem(String itemId) {
        log.info("[orderService] 실행");
        orderRepository.save(itemId);
    }
}
@Slf4j
@Import(BeanTest.BeanAspect.class)
@SpringBootTest
public class BeanTest {

    @Autowired
    OrderService orderService;

    @Test
    void success(){
        log.info("memberService Proxy={}", orderService.getClass());
        orderService.orderItem("itemA");
    }

    @Aspect
    static class BeanAspect{
        @Around("bean(orderService) || bean(*Repository)")
        public Object doLog(ProceedingJoinPoint joinPoint) throws Throwable {
            log.info("[bean] {}", joinPoint.getSignature());
            return joinPoint.proceed();
        }
    }
}
[bean] void hello.aop.order.OrderService.orderItem(String)
[orderService] 실행
[bean] String hello.aop.order.OrderRepository.save(String)
[orderRepository] 실행

 

 

3. GitHub: 220107 bean


 

GitHub - bsh6463/SpringAOP

Contribute to bsh6463/SpringAOP development by creating an account on GitHub.

github.com

 

Comments