[英]Spring WebMVC 5 - Annotation based Interceptor
如何僅通過注釋配置攔截器(我不喜歡在.XML文件中注冊攔截器,我不使用基於.XML的配置)?
注意:我在互聯網上的示例中看到建議使用org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter
,當我嘗試使用它時,我發現它已棄用
我正在使用SpringBoot-2在SpringWebMVC-5上進行測試
在Spring5中,您可以使用org.springframework.web.servlet.config.annotation.WebMvcConfigurer :
@EnableWebMvc
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(....);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.