这个类和之前的AbstractShiroFilter是平级的,都是OnecPerRequestFilter的子类,我们从他的名字Advice中就能联想到他的用意——AOP,在spring中有很多的advice,也就是通知,比如前置通知,后置通知,最终通知等,这个类允许通过很多方法实现filter中的aop的特点,比如preHandle(前置通知),postHandle(后置通知,但是在抛异常的情况下可能不执行,),afterCompletion(最终通知,一定会执行)。
先看看他的doFilterInternal方法:
public void doFilterInternal(ServletRequest request, ServletResponse response, FilterChain chain)
throws ServletException, IOException {
Exception exception = null;
try {
boolean continueChain = preHandle(request, response);//先调用preHandle,判断能否执行
if (log.isTraceEnabled()) {
log.trace("Invoked preHandle method. Continuing chain?: [" + continueChain + "]");
}

AdviceFilter在Shiro中实现了AOP的概念,提供预处理(preHandle)、后处理(postHandle)和最终处理(afterCompletion)功能。当preHandle返回false时,后续filter和servlet将不再执行。该过滤器的子类包括LogoutFilter和PathMatchingFilter,适用于特定的业务场景。开发者可以根据需求覆写preHandle、postHandle和afterCompletion方法以实现自定义的AOP操作。
最低0.47元/天 解锁文章
2796

被折叠的 条评论
为什么被折叠?



