Rest – Spring 3.0 REST implementation DispatcherServlet cannot find mapping

restspring-mvc

I'm trying to get a simple REST service to work with Spring 3.0 but keep bumping into a blocking error:

No mapping found for HTTP request with URI [/travel/us/nyc/sfo/20091010/1122/true/] in DispatcherServlet with name 'dispatcher'*

However, in the log file it also states:

org.springframework.web.servlet.mvc.annotation.Def aultAnnotationHandlerMapping – Mapped URL path [/travel/us/{from}/{to}/{date}/{time}/{departure}/] onto handler [experiment.SomeController@dd9f85]*

which I read as an indication that there is a mapping from the URI to the experiment.SomeController class as handler.

I must be overlooking a simple error in one of the config files, but after checking everything several times and doing quite a bit of Googling I have not found a solution yet. I already turned on logging for the Spring classes, but that also did not reveal the problem.

Below are the relevant config files and some code snippets, any help is appeciated. The webapp is deployed to Glassfish v2.1 and I'm using the M3 build of Spring 3.0.0 on JDK1.5 on OS X.

The goal is to have the getTripDetails() return an XML version of the tripdetails. Hence the use of the MarshallingView.

From web.xml:

<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherSe rvlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

From dispatcher-servlet.xml:

<context:annotation-config />
<context:component-scan base-package="net.vermaas.reisadvies.server" />

<bean class="org.springframework.web.servlet.mvc.annotat ion.DefaultAnnotationHandlerMapping">
<property name="alwaysUseFullPath" value="true"/>
</bean>

<bean id="viewResolver" class="org.springframework.web.servlet.view.Conten tNegotiatingViewResolver">
<property name="mediaTypes">
<map>
<entry key="xml" value="application/xml"/>
</map>
</property>
<property name="viewResolvers">
<list>
<bean class="org.springframework.web.servlet.view.BeanNa meViewResolver"/>
<bean class="org.springframework.web.servlet.view.Intern alResourceViewResolver">
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</list>
</property>
</bean>

<bean id="marshaller" class="org.springframework.oxm.xstream.XStreamMars haller">
</bean>

<bean id="content" class="org.springframework.web.servlet.view.xml.Ma rshallingView">
<property name="contentType" value="application/xml" />
<property name="marshaller" ref="marshaller"/>
</bean>

The controller class:

@Controller
public class SomeController {

static Logger logger = Logger.getLogger(SomeController.class);

public SomeController() {
}

@RequestMapping(value="/travel/us/{from}/{to}/{date}/{time}/{departure}", method=RequestMethod.GET)

public ModelAndView getTripDetails(@PathVariable String from,
@PathVariable String to,
@PathVariable String date,
@PathVariable String time,
@PathVariable boolean departure, Model model) {

logger.debug("getTripDetails"); // not logged

// Do some stuff
TripDetails td = ...

ModelAndView mav = new ModelAndView();
mav.setViewName("content");
mav.addObject("tripDetails", td);

return mav;

}

}

Any thoughts on what's wrong? Or a pointer to a working example of a REST service with Spring 3.0 that has XML as output?

Regards,
Gero

Best Solution

I too ran into the same issue, and the way it works with Spring 3.0 is bu replaceing /* in the url-pattern to /

Related Question