spring-custom-aop -> spring-aop (#1489)
This commit is contained in:
committed by
GitHub
parent
9472f0dd65
commit
b6e271f1f0
@@ -0,0 +1,13 @@
|
||||
package org.baeldung;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package org.baeldung;
|
||||
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
import org.aspectj.lang.annotation.Aspect;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Aspect
|
||||
@Component
|
||||
public class ExampleAspect {
|
||||
|
||||
@Around("@annotation(LogExecutionTime)")
|
||||
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
|
||||
final long start = System.currentTimeMillis();
|
||||
|
||||
final Object proceed = joinPoint.proceed();
|
||||
|
||||
final long executionTime = System.currentTimeMillis() - start;
|
||||
|
||||
System.out.println(joinPoint.getSignature() + " executed in " + executionTime + "ms");
|
||||
|
||||
return proceed;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.baeldung;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
public @interface LogExecutionTime {
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package org.baeldung;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class Service {
|
||||
|
||||
@LogExecutionTime
|
||||
public void serve() throws InterruptedException {
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user