[英]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.