详解SpringBoot AOP 拦截器(Aspect注解方式)

qqstrategy55120 14 0 pdf 2022-05-25 03:05:54

常用用于实现拦截的有:Filter、HandlerInterceptor、MethodInterceptor第一种Filter属于Servlet提供的,后两者是spring提供的,HandlerInterceptor属于Spring MVC项目提供的,用来拦截请求,在MethodInterceptor之前执行。这个不在本文范围,具体使用之前已经写过SpringBoot的MethodInterceptor是AOP项目中的拦截器,它拦截的目标是方法,即使不是Controller中的方法。实现MethodInterceptor拦截器大致也分为两种,一种是实现MethodInterceptor接口,另一种利用Aspect的注解或配置。如果请求show2则不会被拦截。注意: 1、在application.properties中也不需要添加spring.aop.auto=true,因为这个默认就是true,值为true就是启用@EnableAspectJAutoProxy注解了。当你需要统计请求的响应时间时MethodInterceptor将不太容易做到,因为它可能跨越很多方法或者只涉及到已经定义好的方法中一部分代码。Filter是Servlet规范规定的,不属于spring框架,也是用于请求的拦截。

详解SpringBoot AOP 拦截器(Aspect注解方式)

详解SpringBoot AOP 拦截器(Aspect注解方式)

详解SpringBoot AOP 拦截器(Aspect注解方式)

用户评论
请输入评论内容
评分:
暂无评论