让我将我的问题简化如下:
我有一个名为project-parent 的Java Maven 项目,其中有多个子模块项目。
其中一个项目名为project-common,我将整个项目中使用的所有自定义Spring AOP Aspects都放在那里。我已经在project-common 中编写了单元测试,并且该方面按照我在单元测试中的预期正常工作。
然后,我想将这些方面应用到其他模块中。其中一个子模块称为项目服务。我应用于服务中方法的方面应该在服务方法之前和之后进行身份验证管理。但是,我发现这些方面在服务运行时不起作用。此外,project-service 对 project-common 具有 Maven 依赖性。
项目结构如下
project-parent
-- project-common (in which define the aspect)
-- project-service (where my aspect is used)
...
-- other submodules omitted for simplicity
Run Code Online (Sandbox Code Playgroud)
我的方面定义如下:
@Aspect
@Component
public class RequestServiceSupportAspect {
@Pointcut(value = "@annotation(RequestServiceSupport)")
public void matchMethod() {
// pointcut
}
@Around("matchMethod()")
public Object basicAuthSupport(ProceedingJoinPoint joinPoint) {
...
}
}
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface RequestServiceSupport {
}
Run Code Online (Sandbox Code Playgroud)
我的服务使用方面是这样的:
public class RequestServiceImpl implements RequestService {
...
@RequestServiceSupport …Run Code Online (Sandbox Code Playgroud)