【发布时间】:2023-03-22 01:54:01
【问题描述】:
场景
2x 相同的拦截器在相同的 EJB 中的 2 种方法:
...
@Interceptors(PerformanceAuditor.class)
public Date refreshIfNecessary() {
// there is also the PerformanceAuditor-Interceptor on this method
Pair<Date,String> lastImportDate = importDbDAO.findLatestImportLog();
someContainer.reloadIfNecessary(lastImportDate);
return lastImportDate.getLeft();
}
@Interceptors(PerformanceAuditor.class)
public boolean checkAndRefreshIfNecessary(final Date importDate) {
Date lastImportDate = refreshIfNecessary();
return lastImportDate.after(importDate);
}
...
现在我们在外部调用这个 EJB 的方法,结果如下:
- 调用 refreshIfNecessary() -> PerformanceAuditor 被调用 2 次strong>
- 调用 checkAndRefreshIfNecessary() -> PerformanceAuditor 也被调用 2 次strong>! (但预计是 3 次,因为多了一层嵌套!)
那么这里发生了什么?
【问题讨论】:
标签: java jakarta-ee ejb interceptor