XML-free Spring 3.1 No mapping found for HTTP request
java, spring, spring-mvc, tomcat7, url-mapping
Solution
I guess that the jsp are being rendered by the DispatcherServlet, it's discussed in the similar question
You should consider using a more specific mappings both in `HomeController` and in the `WebApplicationInitializer`.
Problem
I've scoured google, stackoverflow, and every forum I can look at for a few days and my keyboard is in dire risk of being the target of a headbutt. I'm running a very small Spring 3.1 MVC with an XML-free setup. The problem is that when I start it up I see; ``` INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/start.action],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.xxxxxx.info.HomeController.start(javax.servlet.http.HttpServletRequest) INFO : org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping - Mapped "{[/*],methods=[],params=[],headers=[],consumes=[],produces=[],custom=[]}" onto public org.springframework.web.servlet.ModelAndView com.xxxxxx.info.HomeController.home(java.util.Locale,org.springframework.ui.Model) ``` Yet when I try to hit either of those URLs I see my logging statements inside my controller fire and then immediately get; ``` INFO : com.xxxxxx.info.HomeController - Welcome home! the client locale is en_US WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/WEB-INF/jsps/home.jsp] in DispatcherServlet with name 'dispatcher' ``` Here are my source files. Initializer - ``` public class Initializer implements WebApplicationInitializer { public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); } } ``` MvcConfig - ``` @Configuration @EnableWebMvc @ComponentScan(basePackages = "com.xxxxxx.info") public class MvcConfig { @Bean public InternalResourceViewResolver configureInternalResourceViewResolver() { InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/jsps/"); resolver.setSuffix(".jsp"); return resolver; } } ``` Controller - ``` @Controller public class HomeController { private static final Logger logger = LoggerFactory.getLogger(HomeController.class); /** Simply selects the home view to render by returning its name. */ @RequestMapping(value = "/*") public ModelAndView home(Locale locale, Model model) { logger.info("Welcome home! the client locale is " + locale.toString()); Date date = new Date(); DateFormat dateFormat = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG, locale); String formattedDate = dateFormat.format(date); model.addAttribute("serverTime", formattedDate); return new ModelAndView( "home", model.asMap() ); } @RequestMapping( value = "/start.action") public ModelAndView start(HttpServletRequest request) { logger.info("Starting!"); return new ModelAndView( "start", null ); } } ``` Changing the dispatcher mapping to "/" as many posts I found suggested seem to break it entirely. If I restart the server with "/" then nothing is reported by Spring, nothing gets mapped, just a tomcat startup log and nothing else works. My file structure is - ``` | com.xxxxxx.info - Initializer.java - MvcConfig.java - HomeController.java | src | main | webapp | WEB-INF | jsps - home.jsp - start.jsp ``` So it appears to hit my controller correctly but when it gets the view name it doesn't resolve to the right place. What am I missing here, this seems like something simple I've overlooked...