0

所以,我一直在尝试使用 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;
}

最后是main方法的相关部分。

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

Guitarist 类正在实现执行者接口。

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

4

1 回答 1

0

注释中没有继承。在Guitaritst课堂上,当重写perform()方法时,你也应该注释它。

于 2013-04-12T19:32:24.590 回答