Spring WebMVC 5 - 基于注解的拦截器
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(....);
}
}
如何仅通过注释配置拦截器(我不喜欢在 .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(....);
}
}