In my spring application, I using the configuration based on java code instead xml files. When I try access any page from my application, the browser is redirect to the correct mapped url, but I still face a 404 error page.
My controller class is created this way:
@Controller
@RequestMapping(value="acesso")
public class AcessoController {
@RequestMapping(value="login")
public ModelAndView login() {
ModelAndView mav = new ModelAndView();
mav.setViewName("acesso/login");
return mav;
}
}
My WebAppInitializer.java is this:
@Order(value=1)
public class WebAppInitializer implements WebApplicationInitializer {
@SuppressWarnings("resource")
@Override
public void onStartup(ServletContext container) {
// Create the 'root' Spring application context
AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext();
rootContext.register(WebAppConfig.class);
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext jspContext = new AnnotationConfigWebApplicationContext();
jspContext.register(JspDispatcherConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic jsp_dispatcher = container.addServlet("jsp_dispatcher", new DispatcherServlet(jspContext));
jsp_dispatcher.setLoadOnStartup(1);
jsp_dispatcher.addMapping("*.jsp");
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext jsonContext = new AnnotationConfigWebApplicationContext();
jsonContext.register(JsonDispatcherConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic json_dispatcher = container.addServlet("json_dispatcher", new DispatcherServlet(jsonContext));
json_dispatcher.setLoadOnStartup(2);
json_dispatcher.addMapping("*.json");
// Create the dispatcher servlet's Spring application context
AnnotationConfigWebApplicationContext xmlContext = new AnnotationConfigWebApplicationContext();
xmlContext.register(XmlDispatcherConfig.class);
// Register and map the dispatcher servlet
ServletRegistration.Dynamic xml_dispatcher = container.addServlet("xml_dispatcher", new DispatcherServlet(jspContext));
xml_dispatcher.setLoadOnStartup(3);
xml_dispatcher.addMapping("*.xml");
}
}
My jspDispatcherConfig.java is this:
@Configuration
@Import(WebAppConfig.class)
public class JspDispatcherConfig {
@Bean
public ViewResolver viewResolver() {
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/view/jsp/");
viewResolver.setSuffix(".jsp");
return viewResolver;
}
}
In my folder WEB-INF, I have the following structure:
-view
--json
--jsp
---acesso
----login.jsp
---erro
----publico
----privado
---privado
----admin.jsp
----customer.jsp
--xml
Anyone can tell me what I am doing wrong here?