@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface iface1{
}
@Target:
@Target说明了Annotation所修饰的对象范围:Annotation可被用于 packages、types(类、接口、枚举、Annotation类型)、类型成员(方法、构造方法、成员变量、枚举值)、方法参数和本地变量(如循环变量、catch参数)。在Annotation类型的声明中使用了target可更加明晰其修饰的目标。
@Retention:
@Retention定义了该Annotation被保留的时间长短:某些Annotation仅出现在源代码中,而被编译器丢弃;而另一些却被编译在class文件中;编译在class文件中的Annotation可能会被虚拟机忽略,而另一些在class被装载时将被读取(请注意并不影响class的执行,因为Annotation与class在使用上是被分离的)。使用这个meta-Annotation可以对 Annotation的“生命周期”限制。
@Aspect
@Component
public class Aspect11{
@Pointcut("@annotation(com.x.a.d.model.annotation.iface1)")
public void advice() {}
@AfterReturning(pointcut="advice()", returning="result")
public void afterReturning(JoinPoint jp, Object result) {
//pointcut
});
}
}
}