So I've setup a spring mvc 3.1 project from scratch and am not using any xml. Thing is my controllers are not getting registered. There are no errors what so ever its like the controller doesn't exist.
The index page loads when I run the application but when I try the url thats mapped nothing happens.
The console shows no errors and I have no build errors.
My Initializer class looks like this:
Code:@Configuration public class Initializer implements WebApplicationInitializer { public void onStartup(ServletContext container) throws ServletException { logger.info("Loading.."); System.out.print("YALLO"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(AppConfig.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
My configuration class looks like this:
Controller looks like this:Code:@Configuration @ComponentScan(basePackages = "com.yardy.controllers") public class DispatcherConfig { private static final Logger logger = LoggerFactory.getLogger(DispatcherConfig.class); @Bean public InternalResourceViewResolver configureInternalResourceViewResolver() { logger.error("HELLO"); InternalResourceViewResolver resolver = new InternalResourceViewResolver(); resolver.setPrefix("/WEB-INF/views/"); resolver.setSuffix(".jsp"); return resolver; } }
Code:package com.yardy.controllers; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @Controller public class YardyController { private static final Logger logger = LoggerFactory.getLogger(YardyController.class); @RequestMapping(value = "/yardy") public String yardy() { System.out.print("Testing.."); logger.info("Welcome home!"); System.out.print("YARDY"); return "yardy"; } }
/yardy just 404's thou.
Can anyone give me any insight into this.
Perhaps point out something I'm missing.


Reply With Quote
