本文介绍了哪个接口的(扩展 CrudRepository)删除方法是使用 spring AOP 触发的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

@Repository
public interface UserRepository extends JpaRepository<User, Long> {
}

我正在从我的服务层调用 userRepo.deleteById(1) 并使用 spring AOP 我想在任何 deleteById 被调用时记录接口名称,以便我可以跟踪触发了哪个接口的 deleteById.我想要一个可以给我接口名称线索的输出.

I am calling userRepo.deleteById(1) from my service layer and using spring AOP I want to log the Interface name whenever any deleteById is called so that I can track which interface's deleteById was triggered. I want an output which can give me a clue of the interface name.

joinPoint.getSignature() 返回通用名称,即 void org.springframework.data.repository.CrudRepository.deleteById(Object) 但我想看看 UserRepository 或调用了 deleteById 的任何存储库名称.

joinPoint.getSignature() returns the generic name i.e. void org.springframework.data.repository.CrudRepository.deleteById(Object) and but I want to see UserRepository or any repository name whose deleteById was called.

推荐答案

这会有帮助吗?

@Before("execution(* org.sec3.jpa.bean.*.deleteById(*)) && target(bean)")
public void getRepositoryName(JoinPoint jp , Object bean ) throws Exception {
    Advised advised = (Advised) bean;
    for(Class<?> clazz : advised.getProxiedInterfaces())
    System.out.println(clazz);
}

印刷品

interface org.sec3.jpa.bean.TestEmployeeRepository
interface org.springframework.data.repository.Repository
interface org.springframework.transaction.interceptor.TransactionalProxy

TestEmployeeRepository 如下

TestEmployeeRepository is as follows

package org.sec3.jpa.bean;

import org.springframework.data.repository.CrudRepository;

public interface TestEmployeeRepository extends JpaRepository<JpaEmployee, Long> {

}

更多细节:操作建议对象

这篇关于哪个接口的(扩展 CrudRepository)删除方法是使用 spring AOP 触发的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-11 03:33