我正在尝试使用 @Around 建议为自定义注释编写方面,但有些原因它不调用。 这是我的代码:
@Aspect
@Component
public class AspectMeasureTime {
@Around(value = "execution(* com.beh.businesslayer..*(..)) && @annotation(measureTime)")
public void measureTime(ProceedingJoinPoint pjp, MeasureTime measureTime) throws Throwable {
/*some code*/
}
}
@Configuration
@ComponentScan(basePackages = {"com.beh"})
@EnableAspectJAutoProxy(proxyTargetClass = false)
public class WebConfig {
}
package com.beh.businesslayer.businessworkflows.pagefetcher;
public class PageFetcherWriter implements ItemWriter, StepExecutionListener {
@MeasureTime("timee")
private void printString(Object s) {
logger.info("entry = " + s);
}
}
package com.beh.businesslayer.businessworkflows.pagefetcher;
@Target({ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
public @interface MeasureTime {
String value();
}
我尝试在没有此注释的情况下创建连接点,它工作正常。尝试使用@annotation(com.beh.businesslayer.businessworkflows.pagefetcher.MeasureTime),它也不起作用。您知道为什么以及它应该是什么样子吗?
最佳答案
如果你要传递一个参数,那么你需要明确地告诉 AspectJ 它正在被传递
@Around(value = "execution(* com.beh.businesslayer..*(..)) && @annotation(measureTime) && args(measureTime)")
public void measureTime(ProceedingJoinPoint pjp, MeasureTime measureTime) throws Throwable {
关于java - 自定义注释方面不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36106277/