Java 为什么从未调用@AfterReturning

Java 为什么从未调用@AfterReturning,java,spring-aop,Java,Spring Aop,我有这个方法,它会返回一个列表: public List<ReportReconciliationEntry> getMissingReports(List<ReportReconciliationEntry> expectedReports, List<GeneratedReportContent> generatedReports){

我有这个方法,它会返回一个列表:

public List<ReportReconciliationEntry> getMissingReports(List<ReportReconciliationEntry> expectedReports,
                                                              List<GeneratedReportContent> generatedReports){
        ...
        return missingReports;
    }
我有另一个类,其中有一个函数,这个很好用:

        @Component
        @Aspect
        @Slf4j
        public class ReportingInfoAspect {

            private final LogWrapper logWrapper;

            private final ReportingAlertProperties properties;

      @AfterReturning(value = "execution(* com.xxx.yyy.zzz.qqq.ReconciliationService.reconcile(..)) && args(windowId)", argNames = "windowId,check",
                returning = "check")
        public void logSuccessfulReportReconciliation(ReconciliationEvent windowId, boolean check){
            String notApplicable = properties.getNotApplicable();
            MDC.put(SYSTEM_COMPONENT, properties.getBpsReportGenerationService());
            ReportingAlertMarker marker = ReportingAlertMarker.builder()
                    .eventType(E90293)
                    .userIdentity(notApplicable)
                    .destinationIp(properties.getDestinationIp())
                    .destinationPort(properties.getDestinationPort())
                    .dataIdentity(notApplicable)
                    .resourceIdentity(notApplicable)
                    .responseCode(200)
                    .build();
            if (check){
                logWrapper.logInfo(marker, "All reports for windowId {} were generated successfully", windowId.windowId);
            }
        }
  }
我发现了问题。 getMissingReports方法是从同一类中的另一个方法调用的。这是一种自调用的情况,该方法从未通过代理调用过

这是该类的外观:

   @Component
    @Aspect
    @Slf4j
    public class ReportingAlertAspect {

        private final LogWrapper logWrapper;

        private final ReportingAlertProperties properties;

        public ReportingAlertAspect(final ReportingAlertProperties properties, final LogWrapper logWrapper) {
            this.logWrapper = logWrapper;
            this.properties = properties;
        }
....
}
@Service
@RequiredArgsConstructor
public class ReconciliationService {

    private final ReconciliationRepository reconciliationRepository;

    private final ReportSafeStoreClientService reportSafeStoreClientService;

    @Handler
    public whatever whatever() {
      ...
      getMissingReports()
    }

}

您可以找到更多信息

当切入点表达式条件最小时,是否调用AfterReturning方法,例如仅执行?还要确认对账服务是否是一个bean,是否使用方面和组件以及扫描的组件对方面进行了注释。否,未调用它。为确保所有必需的步骤都已就绪,是否已启用Proxy注释?如果是,请在此处共享相关类的完整代码。@R.G我添加了代码。很好,您发现了这个问题。在使用Spring AOP时,这是一个非常常见的错误。如果代码是完整共享的,那么可能已经有人为您指出了它。按照我的说法,这个问题不会给出导致这个问题的实际代码的全貌。您可以更新问题并提供答案或将其删除。
@Service
@RequiredArgsConstructor
public class ReconciliationService {

    private final ReconciliationRepository reconciliationRepository;

    private final ReportSafeStoreClientService reportSafeStoreClientService;

    @Handler
    public whatever whatever() {
      ...
      getMissingReports()
    }

}