samedi 18 avril 2015

Spring controller not recognized

I'm trying to set up a simple spring mvc application using class configuration and without web.xml. For some reason it appears that my controller is not being properly scanned during the component scan.


My projet is as following:



src/main/java
-org.webapp.mvc
-config
WebAppInitializer
WebConfig
-controllers
SimpleController

src/main/webapp
-hello.jsp
-index.jsp


WebAppInitializer:



public class WebAppInitializer implements WebApplicationInitializer {

@Override
public void onStartup(ServletContext servletContext) throws ServletException {
WebApplicationContext context = getContext(); //spring configuration context
servletContext.addListener(new ContextLoaderListener(context));
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context));
dispatcher.setLoadOnStartup(1);
dispatcher.addMapping("/*"); //URL mapping
}

private AnnotationConfigWebApplicationContext getContext() {
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
context.setConfigLocation("org.webapp.mvc.config.WebConfig");
return context;
}


}


WebConfig:



@Configuration
@EnableWebMvc
@ComponentScan(basePackages = "org.webapp.mvc.controllers")
public class WebConfig {

}


SimpleController:



@Controller
public class SimpleController {

@RequestMapping(value = "/greeting")
public String test(Model model){
model.addAttribute("greeting", "Hello World");
return "hello.jsp";
}

}


Supposedly 'localhost:8080/project/greeting' should serve 'hello.jsp', but it shows that there's no metching mapping for the URI:



03:22:15.385 [http-nio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - DispatcherServlet with name 'DispatcherServlet' processing GET request for [/project/greeting]
03:22:15.385 [http-nio-8080-exec-3] WARN o.s.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/project/greeting] in DispatcherServlet with name 'DispatcherServlet'
03:22:15.385 [http-nio-8080-exec-3] DEBUG o.s.web.servlet.DispatcherServlet - Successfully completed request


Any idea what am I doing wrong?


[update] Adding debug:



03:22:08.824 [localhost-startStop-1] INFO o.s.web.servlet.DispatcherServlet - FrameworkServlet 'DispatcherServlet': initialization started
03:22:08.828 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate MultipartResolver with name 'multipartResolver': no multipart request handling provided
03:22:08.829 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
03:22:08.872 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver'
03:22:08.872 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate LocaleResolver with name 'localeResolver': using default [org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver@587b4b84]
03:22:08.874 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
03:22:08.880 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.theme.FixedThemeResolver'
03:22:08.880 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate ThemeResolver with name 'themeResolver': using default [org.springframework.web.servlet.theme.FixedThemeResolver@7e02662a]
03:22:08.886 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'
03:22:08.906 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Looking for URL mappings in application context: Root WebApplicationContext: startup date [Sat Apr 18 03:22:08 IDT 2015]; root of context hierarchy
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'environment': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'systemProperties': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'systemEnvironment': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'servletContext': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'contextParameters': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'contextAttributes': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'messageSource': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'applicationEventMulticaster': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.w.s.h.BeanNameUrlHandlerMapping - Rejected bean name 'lifecycleProcessor': no URL paths identified
03:22:08.907 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping'
03:22:08.908 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'
03:22:08.916 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Looking for URL mappings in application context: Root WebApplicationContext: startup date [Sat Apr 18 03:22:08 IDT 2015]; root of context hierarchy
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalRequiredAnnotationProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.internalCommonAnnotationProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'environment': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'systemProperties': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'systemEnvironment': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'servletContext': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'contextParameters': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'contextAttributes': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'messageSource': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'applicationEventMulticaster': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.w.s.m.a.DefaultAnnotationHandlerMapping - Rejected bean name 'lifecycleProcessor': no URL paths identified
03:22:08.918 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'
03:22:08.918 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - No HandlerMappings found in servlet 'DispatcherServlet': using default
03:22:08.921 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
03:22:08.924 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter'
03:22:08.926 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
03:22:08.928 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter'
03:22:08.930 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'
03:22:09.049 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter'
03:22:09.049 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - No HandlerAdapters found in servlet 'DispatcherServlet': using default
03:22:09.053 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
03:22:09.063 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerExceptionResolver'
03:22:09.064 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver'
03:22:09.069 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.annotation.ResponseStatusExceptionResolver'
03:22:09.070 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver'
03:22:09.085 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver'
03:22:09.085 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - No HandlerExceptionResolvers found in servlet 'DispatcherServlet': using default
03:22:09.088 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
03:22:09.093 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator'
03:22:09.093 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate RequestToViewNameTranslator with name 'viewNameTranslator': using default [org.springframework.web.servlet.view.DefaultRequestToViewNameTranslator@18abaed]
03:22:09.096 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.view.InternalResourceViewResolver'
03:22:09.114 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.view.InternalResourceViewResolver'
03:22:09.114 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - No ViewResolvers found in servlet 'DispatcherServlet': using default
03:22:09.119 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
03:22:09.128 [localhost-startStop-1] DEBUG o.s.b.f.s.DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.web.servlet.support.SessionFlashMapManager'
03:22:09.128 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Unable to locate FlashMapManager with name 'flashMapManager': using default [org.springframework.web.servlet.support.SessionFlashMapManager@726c87e9]
03:22:09.128 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Published WebApplicationContext of servlet 'DispatcherServlet' as ServletContext attribute with name [org.springframework.web.servlet.FrameworkServlet.CONTEXT.DispatcherServlet]
03:22:09.128 [localhost-startStop-1] INFO o.s.web.servlet.DispatcherServlet - FrameworkServlet 'DispatcherServlet': initialization completed in 304 ms
03:22:09.128 [localhost-startStop-1] DEBUG o.s.web.servlet.DispatcherServlet - Servlet 'DispatcherServlet' configured successfully

Aucun commentaire:

Enregistrer un commentaire