为什么不调用@AfterReturning

问题描述 投票:0回答:1

我有这个方法,它的确返回列表:

public List<ReportReconciliationEntry> getMissingReports(List<ReportReconciliationEntry> expectedReports,
                                                              List<GeneratedReportContent> generatedReports){
        ...
        return missingReports;
    }

但是永远不会调用此方法:

    @AfterReturning(value = "execution(* com.XXX.YYY.ZZZ.service.ReconciliationService.getMissingReports(..)) && args(expectedReports,generatedReports)", argNames = "expectedReports,generatedReports,missingReports",  returning = "missingReports")
public void logReportReconciliationException(List<ReportReconciliationEntry> expectedReports, List<GeneratedReportContent> generatedReports, List<ReportReconciliationEntry> missingReports) {
                final String notApplicable = properties.getNotApplicable();
                ReportingAlertMarker marker = ReportingAlertMarker.builder()
                        .eventType(E90217)
                        .userIdentity(notApplicable)
                        .destinationIp(properties.getDestinationIp())
                        .destinationPort(properties.getDestinationPort())
                        .dataIdentity(notApplicable)
                        .resourceIdentity(notApplicable)
                        .responseCode(404)
                        .build();
                MDC.put(SYSTEM_COMPONENT, properties.getBpsReportGenerationService());
                System.out.println(missingReports);
                logWrapper.logError(marker, "SDGFHDZFHDFR!!");
            }

我用断点检查第一个方法的返回。它确实返回一个列表,但是尽管IDE显示了“导航到AOP建议”图标,但从未调用@AfterReturning。我想念什么?

这是我的班级样子:

   @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;
        }
....
}

我有另一个带有函数的类,这个类很好用:

        @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);
            }
        }
  }
java spring-aop
1个回答
0
投票

我发现了问题。从同一类中的另一个方法调用了getMissingReports方法。这是自调用的情况,从未通过代理调用该方法。

© www.soinside.com 2019 - 2024. All rights reserved.