AbstractAnnotationConfigDispatcherServletInitializer无法正常运行

时间:2018-06-21 08:09:04

标签: java spring-mvc

这是我的Spring Inialization的DispatcherServletInitializer类

  public class MyDispatcherServletInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
            @Override
            protected Class<?>[] getRootConfigClasses() {
                return null;
            }

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

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

这是我的WelcomeController类

@Controller
public class WelcomeController {

    @RequestMapping("/")
    public ModelAndView hello(HttpServletRequest req, HttpServletResponse resp) {
        return new ModelAndView("hello-world");
    }
}

这是我的AppConfig类

@EnableWebMvc
@Configuration
@ComponentScan("demo.spring.controllers")
public class AppConfig {

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

请为我提供正确的解决方案以使其正常运行...

0 个答案:

没有答案