只需执行以下操作:
@EnableWebMvc@Configurationpublic class WebConfig extends WebMvcConfigurerAdapter { @Bean LocaleInterceptor localInterceptor() { return new LocalInterceptor(); } @Override public void addInterceptors(InterceptorRegistry registry) { registry.addInterceptor(localeInterceptor()); }}当然,
LocaleInterceptor需要在某处(XML,Java Config或使用批注)将其配置为Spring
bean,以便
WebConfig注入相关字段。
可以在此处找到有关Spring
MVC配置的常规自定义文档,特别是对于Interceptor,请参阅本节。



