I want to override the default RequestMappingHandlerMapping as follows:
@Configuration
public static class VersionConfig extends WebMvcConfigurationSupport {
@Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new VersionRequestMappingHandlerMapping();
}
}
where VersionRequestMappingHandlerMapping simply overrides some stub methods:
@Component
public class VersionRequestMappingHandlerMapping extends RequestMappingHandlerMapping {
@Override protected RequestCondition<?> getCustomTypeCondition(Class<?> handlerType) {
VersionRange typeAnnotation = AnnotationUtils.findAnnotation(handlerType, VersionRange.class);
return (typeAnnotation != null) ? new VersionRangeRequestCondition(typeAnnotation.value()) : null;
}
@Override
protected RequestCondition<?> getCustomMethodCondition(Method method) {
VersionRange methodAnnotation = AnnotationUtils.findAnnotation(
method, VersionRange.class);
return (methodAnnotation != null) ? new VersionRangeRequestCondition(methodAnnotation.value()) : null;
}
}
The issue is that because I am extending WebMvcConfigurationSupport in my config, WebMvcAutoConfiguration fails it's conditional:
@ConditionalOnMissingBean(WebMvcConfigurationSupport.class)
public class WebMvcAutoConfiguration {
I think the main issue is that the method :
@Bean
public RequestMappingHandlerAdapter requestMappingHandlerAdapter() {
in WebMvcConfigurationSupport does too much work in the sense that it doesn't simply create a new instance of RequestMappingHandlerAdapter so if I had to create my own @bean returning a RequestMappingHandlerAdapter I would have to paste large chunks of code from WebMvcConfigurationSupport. If we had some factory available, I would just override that to inject my version instead.
There was a similar discussion reported on http://stackoverflow.com/questions/22267191/is-it-possible-to-extend-webmvcconfigurationsupport-and-use-webmvcautoconfigurat but the workaround only worked because it is invoking methods on the existing bean, not overriding them like in my case.
I'm willing to attempt a patch but I'd rather take up some comments/suggestions first.
I want to override the default RequestMappingHandlerMapping as follows:
where VersionRequestMappingHandlerMapping simply overrides some stub methods:
The issue is that because I am extending WebMvcConfigurationSupport in my config, WebMvcAutoConfiguration fails it's conditional:
I think the main issue is that the method :
in WebMvcConfigurationSupport does too much work in the sense that it doesn't simply create a new instance of RequestMappingHandlerAdapter so if I had to create my own @bean returning a RequestMappingHandlerAdapter I would have to paste large chunks of code from WebMvcConfigurationSupport. If we had some factory available, I would just override that to inject my version instead.
There was a similar discussion reported on http://stackoverflow.com/questions/22267191/is-it-possible-to-extend-webmvcconfigurationsupport-and-use-webmvcautoconfigurat but the workaround only worked because it is invoking methods on the existing bean, not overriding them like in my case.
I'm willing to attempt a patch but I'd rather take up some comments/suggestions first.