java - 为什么 Spring-AOP 切入点适用于 save(..) 而不是 saveAll(..)
问题描述
我有一个这样的 Spring-Data 存储库:
package com.example.demo;
@RepositoryRestResource
public interface FooRepository extends JpaRepository<Foo, Long> {
@Override
<S extends Foo> S save(S entity);
@Override
<S extends Foo> List<S> saveAll(Iterable<S> entities);
}
像这样的一个方面:
@Aspect
@Component
public class FooAspect {
@Before("execution(* org.springframework.data.repository.CrudRepository.save(*))")
void crudSaveBefore(JoinPoint joinPoint) throws Throwable {
System.out.println("crud save");
}
@Before("execution(* com.example.demo.FooRepository.save(*))")
void fooSaveBefore(JoinPoint joinPoint) throws Throwable {
System.out.println("foo save");
}
@Before("execution(* org.springframework.data.repository.CrudRepository.saveAll(*))")
void crudSaveAll(JoinPoint joinPoint) throws Throwable {
System.out.println("crud save all");
}
@Before("execution(* com.example.demo.FooRepository.saveAll(*))")
void fooSaveAll(JoinPoint joinPoint) throws Throwable {
System.out.println("foo save all");
}
}
当我运行fooRepository.save(..)
时,在控制台中我看到:foo save
当我运行fooRepository.saveAll(..)
时,在控制台中我看到foo save all
并且crud save all
我希望saveAll
只截取FooRepository
风味,因为我直接切入 package.class.method。这似乎奏效了save
,但不是saveAll
。
这是因为 argssaveAll
吗Iterable
?还是泛型在这里发生某种类型的擦除?还有什么?
解决方案
推荐阅读
- reactjs - 以一定间隔渲染标记
- c# - 如何使 Unity 游戏对象变量只能从检查器编辑
- android - Android 聊天气泡概述了自定义设计
- javascript - 完整日历 REACT JS - 如何禁用拖动到反向背景事件
- python - 防止 Matplotlib 将绘图拉伸到仅绘图区域的 bbox
- python - 如何在 Flask Framework 中更改后端 URL
- python - 在 Pyspark 中过滤具有空数组的列
- python - 在 mac big sur 上安装其他版本的 python 后,pyenv 版本不显示任何内容
- python - 如何在烧瓶方法中分配函数参数?
- java - performClick() 产生 StackOverflowError