Creating custom annotations - andretti1977/linux-commands GitHub Wiki
In SpringBoot you can create a custom annotation this way:
build.gradle:
dependencies {
compile('org.springframework.boot:spring-boot-starter')
compile('org.springframework.boot:spring-boot-starter-aop')
}
Create then an interface:
package com.criptalia.fundsoperations.service;
import java.lang.annotation.*;
/**
* Created by alberto on 11/05/18.
*/
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface IntensiveTest {
}
Create an aspect running the interface
package com.criptalia.fundsoperations.service;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;
/**
* Created by alberto on 11/05/18.
*/
@Aspect
@Component
public class IntensiveTestAspect {
@Around("@annotation(com.criptalia.fundsoperations.service.IntensiveTest)")
public Object logExecutionTime(ProceedingJoinPoint joinPoint) throws Throwable {
System.out.println("£££££££££££££££££££££££££££");
return joinPoint.proceed();
}
}