记录实际的存储库类而不是 JPARepository 的 CrudRepository [英] Log the actual repository class instead of CrudRepository of JPARepository

查看:25
本文介绍了记录实际的存储库类而不是 JPARepository 的 CrudRepository的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

预注:真的很惊讶也很生气,为什么我找不到这么简单的东西.

Pre note: Really surprised and annoyed that why cant I find this simple thing.

public Object interceptMethod(ProceedingJoinPoint joinPoint) throws Throwable {
  joinPoint.getTarget(); //returns SimpleJpaRepository
  joinPoint.getSignature().getDeclaringTypeName(); //Returns CrudRepository
}

如何获取实际的存储库名称?

How do I get the actual repository name ?

推荐答案

获取实际仓库名称的一种方法

One way of getting the actual repository name

@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

package org.sec3.jpa.bean;

import org.springframework.data.repository.CrudRepository;

public interface TestEmployeeRepository extends JpaRepository<JpaEmployee, Long> {

}

我对类似问题的回答 这里

My answer to a similar question here

这篇关于记录实际的存储库类而不是 JPARepository 的 CrudRepository的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆