gpt4 book ai didi

java - Introductions in Introductions in Aspect Oriented Programming中的@DeclareParents注解

转载 作者:搜寻专家 更新时间:2023-11-01 02:26:27 25 4
gpt4 key购买 nike

我正在使用 Java 注释进行 Spring 面向切面编程。我有一个方面 LogAOP:

@Aspect
public class LogAOP {

@DeclareParents(value="beans.service.*+", //Line 1
defaultImpl= EventImpl.class)
public static Event mixin;

@Before("com.beans.business.businessService() &&" +
"this(abc)")
public void usage(Event abc) {
abc.increment();
}

}

我无法理解@DeclareParents 注释的值属性中第 1 行中“+”符号的意义。因为即使我删除了这个 + 符号,程序也能正常运行。我也在Spring AOP的官方文档中搜索过(http://docs.spring.io/spring/docs/2.5.4/reference/aop.html),那里什么都没有。

最佳答案

在类名或接口(interface)名后使用+ 来匹配该类或接口(interface)及其所有子类。因此,本例中的切入点表达式:

@DeclareParents(value="beans.service.*+",     //Line 1
defaultImpl= EventImpl.class)
public static Event mixin;

...将匹配包 beans.service 中定义的任何接口(interface)或类,以及这些类和接口(interface)的任何子类或实现类。它可能是必需的,因为实现类可能不在 beans.service 包中。在您的情况下,您没有看到效果,因为您的所有实现类可能都在同一个包中。尝试在 beans.service 包中实现一个接口(interface),并将实现类放在不同的包中。我想,到时候您就会看到不同之处。

关于java - Introductions in Introductions in Aspect Oriented Programming中的@DeclareParents注解,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21813113/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com