繁体   English   中英

Spring AOP未检测到自定义注释

[英]Custom annotation not being detected by Spring AOP

因此,我一直在尝试使用Spring AOP,但是一旦我开始使用自定义方法注释,AOP就会停止工作。

这是注释:

package com.test.annotations;

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 Performance {

}

方面:

package com.test.aspects;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class Audience {
    @Pointcut("@annotation(com.test.annotations.Performance)")
    public void performance() {
    }

    @Around("performance()")
    public void beforePerformance(ProceedingJoinPoint jointPoint) throws Throwable{
        System.out.println("The audience is getting ready for the show");

        jointPoint.proceed();

        System.out.println("The show is over, audience's leaving");
    }

}

使用自定义注释的类:

package com.test.performers;

import com.test.annotations.Performance;
import com.test.exceptions.PerformanceException;

public interface Performer {
    @Performance
    void perform() throws PerformanceException;
}

最后是主要方法的相关部分。

Performer kenny = (Performer) context.getBean("guitarist");
kenny.perform();

Guitarist类正在实现表演者接口。

我已经环顾了几个小时,看不到我在做什么错。 谢谢 !

注释中没有继承。 Guitaritst类中,当重写perform()方法时,也应对其进行注释。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM