Created
November 10, 2022 13:51
-
-
Save JonasGroeger/5c2b83f5599910b27067985fbeadf66d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package de.jonasgroeger.aspect; | |
import org.aspectj.lang.ProceedingJoinPoint; | |
import org.aspectj.lang.annotation.Around; | |
import org.aspectj.lang.annotation.Aspect; | |
@Aspect | |
public class LogAspect { | |
@Around("execution(* de.jonasgroeger.aspect.SubmissionService.uploadAttachment(..))") | |
public Object logAroundUploadAttachment(ProceedingJoinPoint joinPoint) throws Throwable { | |
beforeEach(); | |
Object returnValue = joinPoint.proceed(); | |
afterEach(); | |
return returnValue; | |
} | |
private void beforeEach() { | |
System.out.println(" Before"); | |
} | |
private void afterEach() { | |
System.out.println(" After"); | |
} | |
@Around("execution(* de.jonasgroeger.aspect.SubmissionService.uploadAttachments(..))") | |
public Object logAroundUploadAttachments(ProceedingJoinPoint joinPoint) throws Throwable { | |
beforeAll(); | |
Object returnValue = joinPoint.proceed(); | |
afterAll(); | |
return returnValue; | |
} | |
private void beforeAll() { | |
System.out.println("Before all"); | |
} | |
private void afterAll() { | |
System.out.println("After all"); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<dependency> | |
<groupId>org.aspectj</groupId> | |
<artifactId>aspectjrt</artifactId> | |
<version>1.9.9.1</version> | |
</dependency> | |
<dependency> | |
<groupId>org.aspectj</groupId> | |
<artifactId>aspectjweaver</artifactId> | |
<version>1.9.9.1</version> | |
</dependency> | |
</dependencies> | |
<build> | |
<plugins> | |
<plugin> | |
<artifactId>maven-compiler-plugin</artifactId> | |
<version>3.10.1</version> | |
<configuration> | |
<source>11</source> | |
<target>11</target> | |
</configuration> | |
</plugin> | |
<plugin> | |
<groupId>org.codehaus.mojo</groupId> | |
<artifactId>aspectj-maven-plugin</artifactId> | |
<version>1.14.0</version> | |
<configuration> | |
<complianceLevel>11</complianceLevel> | |
<source>11</source> | |
<target>11</target> | |
</configuration> | |
<executions> | |
<execution> | |
<goals> | |
<goal>compile</goal> <!-- use this goal to weave all your main classes --> | |
<goal>test-compile</goal> <!-- use this goal to weave all your test classes --> | |
</goals> | |
</execution> | |
</executions> | |
<dependencies> | |
<dependency> | |
<groupId>org.aspectj</groupId> | |
<artifactId>aspectjtools</artifactId> | |
<version>1.9.9.1</version> | |
</dependency> | |
</dependencies> | |
</plugin> | |
</plugins> | |
</build> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment