java - 为什么永远不会调用@AfterReturning
问题描述
我有这个方法,它确实返回一个列表:
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 建议”图标。我错过了什么?
这是我的课的样子:
@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()
}
}
你可以在这里找到更多信息
推荐阅读
- apache-spark - 如何使用 SPARK 连接到 IBM COS(云对象存储),如何解决“No FileSystem for scheme:cos”
- c - ARM 是否假设所有 Cortex-M 微控制器都是小端的?
- java - 为什么我无法在 Android Studio 中解析符号“setText”?
- r - 如何在ggplot中将文本添加到geom_vline
- python - 使用自定义分类索引顺序在 Python 中重新排序热图行
- r - 有没有办法与 unnest_tokens 相反?我想根据唯一 ID 将单词组合成一行
- html - 使用 CSS 将元素置于最前面
- angular - 如何从应用路由模块获取路由?
- reactjs - Material UI - 如何通过 ListItem 链接打开对话框
- python - AttributeError:模块“posts.views”没有属性“add_comment_to_post”