Java 为什么Spring AOP切入点适用于save(..)而不适用于saveAll(..)
我有这样一个Spring数据存储库:Java 为什么Spring AOP切入点适用于save(..)而不适用于saveAll(..),java,spring-boot,aop,spring-aop,pointcut,Java,Spring Boot,Aop,Spring Aop,Pointcut,我有这样一个Spring数据存储库: 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<
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");
}
}
当我运行foosrepository.save(..)
时,在控制台中我看到:foosave
当我运行fooRepository.saveAll(..)
时,在控制台中我看到foo save all
和crud save all
我希望saveAll
只截取foodrepository
风格,因为我直接剪切package.class.method。这似乎适用于save
,但不适用于saveAll
这是因为
saveAll
中的参数是Iterable
?或者泛型中发生了某种类型的类型擦除?还有别的吗?似乎是AOP问题。对于proxyFooRepository.saveAll
,它在表达式之前调用Crudepository.saveAll
>:
AbstractAspectJAdvice 683
似乎是AOP问题。对于proxyFooRepository.saveAll
,它在
表达式之前调用Crudepository.saveAll
>:
AbstractAspectJAdvice 683
如果我知道如何运行此代码,我相信我可以帮助您。请在GitHub上提供一个理想的。那我来看看。(我是Spring noob,但有点像AOP专家。)如果我知道如何运行此代码,我相信我可以帮助您。请在GitHub上提供一个理想的。那我来看看。(我是Spring noob,但有点像AOP专家。)