I have a spring application that uses an embedded Jetty instance. Since I am programmatically defining my web.xml, here is how I am adding the dispatcher.
DispatcherServlet dispatcherServlet = new DispatcherServlet();
dispatcherServlet.setContextClass(
AnnotationConfigWebApplicationContext.class);
ServletHolder holder = new ServletHolder(dispatcherServlet);
holder.setInitOrder(1);
ctx.addServlet(holder, "/example/*");
At the Jetty level I am defining my spring contexts. The initparams are then applied to the Jetty Context.
initParams.put("contextConfigLocation",
"classpath*:resources/spring/*.xml");
...
ctx.setInitParams(initParams);
I do see in the log that it is finding a controller I annotated with @Controller, so I am led to believe that the spring application contexts are loading correctly.
org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping - Mapped URL path [/example/helloWorld] onto handler [example.controllers.HelloWorldController]
in my context i have the following for view resolution
<!-- Resolves view names to protected .jsp resources within the /WEB-INF/views directory -->
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
here is my HelloWorldController
@Controller
public class HelloWorldController {
@RequestMapping("/example/helloWorld")
public ModelAndView helloWorld() {
ModelAndView mav = new ModelAndView("helloWorld");
mav.addObject("message", "Hello World!");
return mav;
}
}
When I point my browser to it "http://localhost:8080/example/helloWorld, I get the following error in the log.
org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/example/helloWorld] in DispatcherServlet with name 'org.springframework.web.servlet.DispatcherServlet-1352529649'
I am not sure if I am setting up the jetty container right, or if I am passing in the dispatcher appropriately to the container. Something is off. Anyone have an idea?