如何解决春季年度中的http 404错误?

时间:2018-01-29 06:13:47

标签: java spring mongodb spring-mvc

我是带有注释的Spring MVC的新手,我只是尝试了一个基本的例子。但我收到HTTP Stats 404错误。我的文件如下: 这是一个maven项目。请求映射是使用的控制器的一部分,而jsp页面仅用list.jsp来显示该消息。

  

错误 - HTTP状态404 - /test1/view/list.jsp

public class ADConfiguration extends WebMvcConfigurerAdapter{

@Override
public void configureViewResolvers(ViewResolverRegistry registry) {
    InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
    System.out.println("hjshjshdjkah");
    viewResolver.setViewClass(JstlView.class);
    viewResolver.setPrefix("/view/");
    viewResolver.setSuffix(".jsp");
    registry.viewResolver(viewResolver);
}
@RequestMapping(value = "/list", method = RequestMethod.GET)    
public ModelAndView list() {
    System.out.println("@@@@@@@@@@@@@@@@@@@@Controller part methods@@@");
    String message = "HELLO SPRING MVC HOW R U";  
    return new ModelAndView("list", "message", message);  

}

公共类ADInitializer扩展AbstractAnnotationConfigDispatcherServletInitializer {

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

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

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

@Override
protected Filter[] getServletFilters() {
    Filter [] singleton = { new com.admin.configuration.CORSFilter() };
    return singleton;
}

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
    /*// TODO Auto-generated method stub
    super.onStartup(servletContext);*/

    AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext();
    ctx.register(ADConfiguration.class);
    ctx.setServletContext(servletContext);

    ServletRegistration.Dynamic servlet = servletContext.addServlet("dispatcher", new DispatcherServlet(ctx));

    servlet.setLoadOnStartup(1);
    servlet.addMapping("/");
}

}

1 个答案:

答案 0 :(得分:0)

它找不到正确的响应路径。不是你的注释错误