The type WebMvcConfigurerAdapter is deprecated
WebMvcConfigurerAdapter 被棄用了,看一下文檔。
* @deprecated as of 5.0 {@link WebMvcConfigurer} has default methods (made * possible by a Java 8 baseline) and can be implemented directly without the * need for this adapter
可以采用直接實現WebMvcConfigurer接口的方式,而不用使用WebMvcConfigurerAdapter
public class MyWebAppConfigurer implements WebMvcConfigurer { @Override public void addInterceptors(InterceptorRegistry registry) { // 多個攔截器組成一個攔截器鏈 // addPathPatterns 用於添加攔截規則 // excludePathPatterns 用戶排除攔截 // RequestInterceptor()為自己定義的攔截器 registry.addInterceptor(new RequestInterceptor()).addPathPatterns("/**"); } }