【发布时间】:2019-10-15 10:22:51
【问题描述】:
我正在尝试创建一个在每次调用 Spring JpaRepository 的 save() 之后运行的 Aspect。我将我的方面定义如下:
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@Aspect
@Component
@Slf4j
public class ProcessAspect {
@Autowired
private ProcessService processService;
@AfterReturning(value = "execution(* com.domain.control.repository.ProcessDao.save())))",
returning = "result")
private void propagateProcess(JoinPoint joinPoint, Object result) {
log.info("Aspect is working, congratulations. Jointpoint {} , result {}", joinPoint, result.toString());
Process process = (process) result;
// do something on the object returned by save()
processService.createOrUpdateProcess(process);
}
}
我的仓库定义如下:
@Repository
public interface ProcessDao extends JpaRepository<Process, String>
如果我以这种方式配置它,那么方面就不起作用了。
如何配置我的方面以在通用 JPA 存储库方法之后运行?
【问题讨论】:
标签: java spring spring-aop