开发者

What is wrong about my embedded jetty spring web application configuration?

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="s开发者_运维问答uffix" 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?


The issue was we were configuring a resourceBase for Jetty that was different than the location in which our JSPs were. We weren't using JSP's orginally. After I saw that, i moved the location of the JSPs to the resource directory. This resolved the issue. Although this presents a security issue, but thats another topic.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜