lundi 25 juillet 2016

Spring MVC - Page Not Found

So here's my project :

WebConfig.java :

@EnableWebMvc
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter{

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/").setViewName("index");
}

public InternalResourceViewResolver internalResourceViewResolver() {

    InternalResourceViewResolver resolver = new         InternalResourceViewResolver();
    //strings to views
    //success from a controller -* prefix/success/suffix
    //success from a controller -* /WEB-INF/pages/success.jsp
    resolver.setPrefix("/WEB-INF/pages/");
    resolver.setSuffix(".jsp");

    return resolver;
}
}

AppInitializer.java :

public class WebAppInitializer implements WebApplicationInitializer{

public void onStartup(ServletContext container) throws ServletException {
    AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
    rootContext.register(WebConfig.class);

    container.addListener(new ContextLoaderListener(rootContext));

    DispatcherServlet dispatcherServlet = new DispatcherServlet(rootContext);

    ServletRegistration.Dynamic registration = container.addServlet("dispatcherServlet", dispatcherServlet);
    registration.setLoadOnStartup(1);
    registration.addMapping("/");
}

}

P.S : my "index.jsp" page is in : /WEB-INF/pages/

And I'm still not getting the index page : it says it's not found. Thanks for your help.




Aucun commentaire:

Enregistrer un commentaire