gpt4 book ai didi

java - 为什么 @AfterReturning 从未被调用

转载 作者:行者123 更新时间:2023-12-01 19:25:07 24 4
gpt4 key购买 nike

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

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!!");
}

我用断点检查第一个方法的返回。它确实返回一个列表,但 @AfterReturning 永远不会被调用,尽管 IDE 显示“导航到 AOP 建议”图标。我错过了什么?

这就是我的类(class)的样子:

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

最佳答案

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

这就是类的样子:

@Service
@RequiredArgsConstructor
public class ReconciliationService {

private final ReconciliationRepository reconciliationRepository;

private final ReportSafeStoreClientService reportSafeStoreClientService;

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

}

您可以找到更多信息here

关于java - 为什么 @AfterReturning 从未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59319563/

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