是否可以通过 war 中的路径为所有 类 添加一些功能?

Is it possible to add some funtctionality for all classes by path in war?

我正在寻找 AspectJ(或其他,如果您知道另一种方法)解决方案来更改满足模式 get* 的所有方法的功能。

是否可以针对整个可部署 war 归档 WEB-INF/classes 中的所有 class 执行此操作,而无需 明确指定任何带有注释的 class或其他,因为在项目中我们有太多class 无法手动标记它们。完全不能接受。

我需要将行 Logger.applyLogging(this.getClass()); 放在所有这些方法的开头。

您可以为该特定包中的所有 getter 创建一个 AroundAdvice。

为此,您需要 2 个 pointCuts - 一个用于包中的所有方法,并结合此包中以 get 开头的所有方法。

然后编写你的 aroundAdvice。

那是一些伪代码:

@Pointcut("within(com.xyz.someapp.trading..*)")
public void thePackagePointCut()

@Pointcut("execution(* get*(..))")
public void allGetters()

@Before("thePackagePointCut() && allGetters()")
public void applyAdvise(JoinPoint jp) {
    // Log before invocation

    // let the pointCut execute the method
}