2
votes

I'm trying to run embedded Jetty server and deploy Spring MVC application into it, but there is a problem of resources mapping - particulary I can't map spring mvc controller so that it can find my JSPs.

Configuration:

  • jetty-8.1.8.v20121106
  • Spring 3.2

Jetty Server Configuration:

    Server server = new Server();

    ServletContextHandler context = new ServletContextHandler();
   //WebAppContext context = new WebAppContext();
    context.setBaseResource(Resource.newClassPathResource("webapp"));
    context.setClassLoader(Thread.currentThread().getContextClassLoader());
    context.setContextPath("/");

    AnnotationConfigWebApplicationContext webAppContext = new AnnotationConfigWebApplicationContext();
    webAppContext.register(WebFaceSpringConfiguration.class);
    webAppContext.setServletContext(context.getServletContext());
    webAppContext.setParent(applicationContext);

    context.addServlet(new ServletHolder(new DispatcherServlet(webAppContext)), "/");

    server.setHandler(context);
    server.setConnectors(jettyConnectors);

Folder webapp is in classpath, but in such configuration I have an error Problem accessing /WEB-INF/pages/main-page.jsp (which is actually located under webapp). So controller method is invoked, but view cannot be resolved.

I tried to use WebAppContext and wildcard mapping for Spring Dispatcher Servlet (/*), but it did not help - controller mapping is ignored or JSP cannot be found.

1
Can you post your error?Sotirios Delimanolis

1 Answers

0
votes

You need to specify a viewresolver, normal way looks this in xml

 <bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:prefix="/WEB-INF/pages/" p:suffix=".jsp"/>