【发布时间】:2019-04-15 10:19:54
【问题描述】:
我有一个注释。
@Target(value = {ElementType.METHOD, ElementType.TYPE})
@Retention(value = RetentionPolicy.RUNTIME)
@Inherited
@Documented
public @interface MyCustomAnnotation{
}
我的 Aspect 类是这样的
@Component
@Aspect
public class MyCustomAsspect{
@AfterReturning(
pointcut="@annotation(MyCustomAnnotation)",
returning="retVal")
public void publishMessage(JoinPoint jp, Object retVal) throws Throwable {
}
}
我的服务类是
@Service
public class ServiceClass{
@MyCustomAnnotation
public Object someMethod(){
return new Object();
}
}
上面提到的类我不知道为什么我的方面不起作用。我是 Spring AOP 的新手。请帮助我,将非常感谢。
【问题讨论】:
-
你的切入点到底是什么?
-
你缺少切入点或切入点不当
-
@annotation(MyCustomAnnotation) 这是我的切入点
-
尝试在 MyCustomAsspect 类上方添加
@EnableAspectJAutoProxy -
@BishalJaiswal 它已经出现在我的 SpringBootApplication 类中
标签: java spring aop spring-aop aspect