2017  Kodetalk | Feedback | Privacy Policy | Terms | About
userimage

In Spring MVC version 5.0.0.RC1 the WebMvcConfigurerAdapter is deprecated, so what is the alternative.

I have upgraded my project from spring 4.x to 5.0.0.RC1 and the bean configuration file i have extended to WebMvcConfigurerAdapter. But now after upgrade to latest spring version the class WebMvcConfigurerAdapter is showing as deprecated. I am trying to find out the alternative of this class provided in spring 5.0.0.RC1.


Thanks

userimage

You can use below way to make things work:

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * 
 * @author Deb 19 May 2017
 *
 */
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = { "com.test.controller" })
public class Resolver implements WebMvcConfigurer {
   @Override
   public void addResourceHandlers(ResourceHandlerRegistry registry) {
      // Your code
   }

   @Bean
   public ViewResolver liteDeviceAwareViewResolver() {
   }
}
userimage

The alternative would be WebMvcConfigurationSupport class. You can use this.

Answer is