今日、私はSpring 4でAOPを管理しようとしていますが、@Aroundアノテーションに問題があります。これは、ポイントカットの後でのみ動作し、@Afterアノテーションのように動作します。何が悪いですか?@Beforeと@Aroundアノテーションの組み合わせの組み合わせは、ポイントカット後にメソッドを呼び出す場合のみです。AOP、Spring 4 MVC、@Around annotation
組み合わせ@Afterと@Beforeは正常に動作します。正直言って、なぜそれがそのように機能するのか分かりません。
私はAOPメソッドの呼び出しを検出するためにいくつかのmockitoを試していますが、動作しません。
私はコンフィギュレーションクラス
@Configuration
@EnableAspectJAutoProxy
@ComponentScan(basePackages = { "my.package.to.aop" })
public class AOPConfiguration {}
AOPのクラスがあります。
@Aspect
@Component
public class SmartLoggerAspect {
@After("execution(* my.package.to.specific.function."
+ "repositories.PagingAndSortingBookRepository.findAll("
+ "org.springframework.data.domain.Pageable) )")
public void afterPage(JoinPoint joinPoint){
System.out.println("\n\n\n\nCALLED AFTER: " + joinPoint.getSignature().getName());
}
@Before("execution(* my.package.to.specific.function."
+ "repositories.PagingAndSortingBookRepository.findAll("
+ "org.springframework.data.domain.Pageable) )")
public void beforePage(JoinPoint joinPoint){
System.out.println("\n\n\n\nCALLED BEFORE: " + joinPoint.getSignature().getName());
}
@Around("execution(* my.package.to.specific.function."
+ "repositories.PagingAndSortingBookRepository.findAll("
+ "org.springframework.data.domain.Pageable) )")
public void aroundPage(JoinPoint joinPoint){
System.out.println("\n\n\n\nCALLED AROUND: " + joinPoint.getSignature().getName());
}
}
をそして私は、私は問題はJoinPoint
代わりのためのProceedindJoinPoint
を使用していると思わそれ
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = { JPAConfig.class, AOPConfiguration.class })
@TestExecutionListeners({ DependencyInjectionTestExecutionListener.class, TransactionalTestExecutionListener.class })
public class AspectTest {
@Autowired
PagingAndSortingBookRepository pagingAndSortingRepo;
@Autowired
SmartLoggerAspect smartLoggerAspect;
JoinPoint joinPoint;
@Test
public void pagingTest(){
pagingAndSortingRepo.findAll(new PageRequest(1, 1));
//verify(smartLoggerAspect, times(1)).afterPage(joinPoint);
}
}
「@ Before' + '@ After' __and__' @ Around'のアドバイスも必要なのはなぜですか? '@Around'のアドバイスでアドバイスを徹底的に試してみませんか? –
私は初心者であり、AOPを使用する多くの方法を試しているからです。私がaBeforeとaAfter関数にコメントしてaroundだけを残しても、同じ問題が残っています。 –
'Pointcut [...]の後でのみ動作します。 –