Skip to content

Instantly share code, notes, and snippets.

@JonasGroeger
Created November 10, 2022 13:51
Show Gist options
  • Save JonasGroeger/5c2b83f5599910b27067985fbeadf66d to your computer and use it in GitHub Desktop.
Save JonasGroeger/5c2b83f5599910b27067985fbeadf66d to your computer and use it in GitHub Desktop.
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");
}
}
<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