|
| 1 | +package com.baeldung.performancemonitor; |
| 2 | + |
| 3 | +import org.aspectj.lang.annotation.Aspect; |
| 4 | +import org.aspectj.lang.annotation.Pointcut; |
| 5 | +import org.springframework.aop.Advisor; |
| 6 | +import org.springframework.aop.aspectj.AspectJExpressionPointcut; |
| 7 | +import org.springframework.aop.interceptor.PerformanceMonitorInterceptor; |
| 8 | +import org.springframework.aop.support.DefaultPointcutAdvisor; |
| 9 | +import org.springframework.context.annotation.Bean; |
| 10 | +import org.springframework.context.annotation.Configuration; |
| 11 | +import org.springframework.context.annotation.EnableAspectJAutoProxy; |
| 12 | + |
| 13 | +@Configuration |
| 14 | +@EnableAspectJAutoProxy |
| 15 | +public class AopConfiguration { |
| 16 | + |
| 17 | + @Pointcut("execution(public int com.baeldung.performancemonitor.Person.getAge())") |
| 18 | + public void monitor() { } |
| 19 | + |
| 20 | + @Pointcut("execution(public void com.baeldung.performancemonitor.Person.setAge(int))") |
| 21 | + public void myMonitor() { } |
| 22 | + |
| 23 | + @Bean |
| 24 | + public PerformanceMonitorInterceptor performanceMonitorInterceptor() { |
| 25 | + return new PerformanceMonitorInterceptor(true); |
| 26 | + } |
| 27 | + |
| 28 | + @Bean |
| 29 | + public Advisor performanceMonitorAdvisor() { |
| 30 | + AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); |
| 31 | + pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.monitor()"); |
| 32 | + return new DefaultPointcutAdvisor(pointcut, performanceMonitorInterceptor()); |
| 33 | + } |
| 34 | + |
| 35 | + @Bean |
| 36 | + public Person person(){ |
| 37 | + return new Person(); |
| 38 | + } |
| 39 | + |
| 40 | + @Bean |
| 41 | + public MyPerformanceMonitorInterceptor myPerformanceMonitorInterceptor() { |
| 42 | + return new MyPerformanceMonitorInterceptor(true); |
| 43 | + } |
| 44 | + |
| 45 | + @Bean |
| 46 | + public Advisor myPerformanceMonitorAdvisor() { |
| 47 | + AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); |
| 48 | + pointcut.setExpression("com.baeldung.performancemonitor.AopConfiguration.myMonitor()"); |
| 49 | + return new DefaultPointcutAdvisor(pointcut, myPerformanceMonitorInterceptor()); |
| 50 | + } |
| 51 | + |
| 52 | +} |
0 commit comments