我有一个包含@EnableMVC
和Configuration
注释的配置类。我扩展了WebMvcConfigurerAdapter
类并重写了addArgumentResolver
方法以添加一个。然而,该方法永远不会被调用。我已经完成了一个系统输出来测试它是否被调用。奇怪的是,我尝试将addInterceptor
方法重写为同一个类,并且它被调用得很好。任何有关这里发生的事情的线索都会受到赞赏。
@Configuration
@ComponentScan("com.fico.cardinal")
@EnableWebMvc
public class WebContextConfig extends WebMvcConfigurerAdapter {
@Bean
public ValidateJson validateJson() {
System.out.println("Created bean validate json");
return new ValidateJson();
}
@Bean
private RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
return new RequestMappingHandlerAdapter();
}
@Bean
public ValidateJsonSchema validateJsonSchema() {
System.out.println("Created bean validate json schema");
return new ValidateJsonSchema();
}
@Override
public void addArgumentResolvers(
List<HandlerMethodArgumentResolver> argumentResolvers) {
super.addArgumentResolvers(argumentResolvers);
argumentResolvers.add(validateJsonSchema());
System.out.println("Added resolver");
// doesn't gets called
}
@Override
public void addInterceptors(InterceptorRegistry registry) {
super.addInterceptors(registry);
registry.addInterceptor(validateJson());
System.out.println("added interceptor");
// gets called
}
编辑:包含完整的配置类
答案 0 :(得分:0)
以我为例
extends WebMvcConfigurationSupport
到
implements WebMvcConfigurer
工作