小编mat*_*ego的帖子

使用 Spring @Configuration 和 MethodInterceptor 拦截带注释的方法

我需要使用 spring-aop 拦截带注释的方法。我已经有了拦截器,它实现了 AOP 联盟的 MethodInterceptor。

这是代码:

@Configuration
public class MyConfiguration {

    // ...

    @Bean
    public MyInterceptor myInterceptor() {
      return new MyInterceptor();
    }
}
Run Code Online (Sandbox Code Playgroud)
@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface MyAnnotation {
    // ...
}
Run Code Online (Sandbox Code Playgroud)
public class MyInterceptor implements MethodInterceptor {

    // ...

    @Override
    public Object invoke(final MethodInvocation invocation) throws Throwable {
        //does some stuff
    }
}
Run Code Online (Sandbox Code Playgroud)

从我过去读到的内容来看,我可以使用 @SpringAdvice 注释来指定拦截器何时应该拦截某些东西,但现在已经不存在了。

谁能帮我?

非常感谢!

卢卡斯

spring-aop aopalliance

5
推荐指数
1
解决办法
4121
查看次数

标签 统计

aopalliance ×1

spring-aop ×1