top.infra.web.servlet.handler.OrderedHandlerInterceptorWebMvcConfigureAdapter Maven / Gradle / Ivy
package top.infra.web.servlet.handler;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import java.util.Comparator;
import java.util.List;
/**
* Created by zhuowan on 2018/5/15 15:28.
* Description:
*/
public abstract class OrderedHandlerInterceptorWebMvcConfigureAdapter extends WebMvcConfigurerAdapter {
private static Comparator> comparator() {
return Comparator.comparingInt(i -> i.getInterceptor().getOrder());
}
public abstract List> addOrderedInterceptors();
@Override
public void addInterceptors(final InterceptorRegistry registry) {
final List> interceptors = this.addOrderedInterceptors();
interceptors
.stream()
.sorted(comparator())
.forEach(i -> registry.addInterceptor(i.getInterceptor()).addPathPatterns(i.getPatterns()));
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy