3

I see @RequestMapping works without having annotated @EnableWebMvc at Java Configuration class level. This looks like @EnableWebMvc is no more required. Can anyone make me understand the flow here?

Here is my working example on displaying simple jsp page using Spring 4.1v.

@Controller
public class AboutUsController {
    @RequestMapping("/home.htm")
    public String showAboutUs() {
        return "entry";
    }
}

@Configuration
@ComponentScan("com.span.controller")
// @EnableWebMvc
public class WebConfig { // extends WebMvcConfigurationSupport {

    @Bean
    public ViewResolver getViewResolver() {
        InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
        viewResolver.setSuffix(".jsp");
        viewResolver.setPrefix("WEB-INF/jsp/");

        return viewResolver;
    }
}

public class StartUp extends
    AbstractAnnotationConfigDispatcherServletInitializer {

    @Override
    protected Class<?>[] getRootConfigClasses() {
        return null;
    }

    @Override
    protected Class<?>[] getServletConfigClasses() {
        return new Class[]{WebConfig.class};
    }

    @Override
    protected String[] getServletMappings() {
        return new String[]{"*.htm"};
    }

}

Thanks.

  • See http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#mvc-servlet-config. Does it work, yes, is it sufficient it might. But the version you use still has the old `DefaultAnnotationHandlerMapping` instead of the newer more powerful/flexible `RequestMappingHandlerMapping` and other classes. – M. Deinum Sep 16 '16 at 13:42
  • Thanks for help. –  Oct 20 '17 at 08:11
  • Are you using SpringBoot? – John John Pichler Aug 24 '18 at 13:39

0 Answers0