Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot extend WebMvcAutoConfigurationAdapter in Spring Boot 1.4

I'd like to update a web project to Spring Boot 1.4 but I'm getting and error.

I'm currently using Spring Boot 1.3.3 and I'm extending WebMvcAutoConfigurationAdapter to map some custom resource hanlders:

@Configuration
public class MvcConfiguration extends WebMvcAutoConfigurationAdapter {

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        super.addResourceHandlers(registry);
        registry.addResourceHandler("/images/users/**").addResourceLocations("http://file-storage/images/users/");
        // ...

}

I noticed that in the new version of SB a constructor was added to WebMvcAutoConfigurationAdapter:

public WebMvcAutoConfigurationAdapter(ResourceProperties resourceProperties,
        WebMvcProperties mvcProperties, ListableBeanFactory beanFactory,
        HttpMessageConverters messageConverters,
        ObjectProvider<ResourceHandlerRegistrationCustomizer> resourceHandlerRegistrationCustomizerProvider) {} 

and this constructor uses ResourceHandlerRegistrationCustomizer that is a package-protected interface, so, basically, from version 1.4 is not possible to extend autoconfiguration.

What is an alternative way to extend autoconfiguration?

like image 517
davioooh Avatar asked Aug 05 '16 13:08

davioooh


1 Answers

There's no need to extend WebMvcAutoConfigurationAdapter to add some custom resource handlers (and never has been). You should extend Spring MVC's WebMvcConfigurerAdapter instead.

like image 134
Andy Wilkinson Avatar answered Oct 19 '22 08:10

Andy Wilkinson