I have a Spring 4 MVC app. When I try to access any URL the application always redirects to the root folder.
My main class:
public class SiteMain implements WebApplicationInitializer {
@Override
public void onStartup(ServletContext container) throws ServletException {
AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext();
dispatcherContext.setConfigLocation("com.mj.cchp.MvcConfig");
container.addListener(new ContextLoaderListener(dispatcherContext));
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/");
}
}
and MVC Config is:
@Configuration
@EnableWebMvc
@ComponentScan
@ImportResource({ "classpath:/WEB-INF/site.xml" })
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addResourceHandlers(ResourceHandlerRegistry registry) {
registry.addResourceHandler("/resources/**").addResourceLocations("/resources/").setCachePeriod(31556926);
}
}
Aucun commentaire:
Enregistrer un commentaire