Add your own annotation to the class or method, and use the characters specified in annotation.
--Environment - Spring AOP 4.3.5 - cglib 2.1_3
The acquisition method is different between the annotation attached to the class and the annotation attached to the method, and I stumbled there. ..
Annotation attached to the class
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
public @interface ClassAnnotation{
String value() default "defalut";
Aspect target class
@ClassAnnotation("Class_01")
public class SampleController {
Realization part of Aspect (PointCat is carried out around)
@Around("@within(ann)")
public void classIntercepter(ProceedingJoinPoint pjp, ClassAnnotation ann) throws Throwable{
System.out.println(ann.value());
pjp.proceed();
Annotation attached to the method
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MethodAnnotation {
String value() default "defalut";
Aspect target method
@MethodAnnotation("Method_01")
public void sampleMethod(
Realization part of Aspect (
@Around("@annotation(ann)")
public void MethodIntercepter(ProceedingJoinPoint pjp, MethodAnnotation ann) throws Throwable{
System.out.println(ann.value());
pjp.proceed();
Realization of Aspect(class)
@Around("@within(com.example.annotation.ClassAnnotation)")
public void classIntercepter(ProceedingJoinPoint pjp) throws Throwable{
pjp.proceed();
Realization of Aspect(Method)
@Around("@annotation(com.example.annotation.MethodAnnotation)")
public void classIntercepter(ProceedingJoinPoint pjp) throws Throwable{
pjp.proceed();
Slightly special Java annotation How to write Spring AOP pointcut specifier Let's utilize Annotation with AspectJ Part 1
Recommended Posts