@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
@Bean
public LocaleInterceptor localeInterceptor() {
return new LocaleInterceptor();
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor( localeInterceptor() );
}
}
原因就是interceptor默认是不被spring context掌管的。所以还添加@bean ,加入的spring 容器下,才可以读取的spring容器内的变量值