[英]Why does Spring-AOP pointcut work for save(..) but not 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
无效。
这是因为saveAll
中的参数是Iterable
吗? 或者 generics 发生了某种类型的擦除? 还有什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.