Note that there are some explanatory texts on larger screens.

plurals
  1. POSpringMVC Restful Service in 3.1.1 doesn't run (in 3.0.3 runs ok)
    primarykey
    data
    text
    <p>I have some problems with new version of Spring. I am doing something wrong or I forget any configuration.</p> <p>Concretly, I am doing a PoC of Restful service with Spring MVC. In Spring 3.0.3 runs correctly but in Spring 3.1 or 3.1.1 doesn't run.</p> <p>My PoC contains:</p> <p>Controller:</p> <pre><code>@Controller public class ProductControllerImpl implements IProductController { private static Product producto = new Product(); @RequestMapping(value = "/products", method = RequestMethod.GET) @ResponseBody public List&lt;Product&gt; getAllProducts() { producto.setId(1L); List&lt;Product&gt; list = new ArrayList&lt;Product&gt;(); list.add(producto); return list; } @RequestMapping(value = "/products/{productId}", method = RequestMethod.GET) @ResponseBody public Product getProductById(Long productId) { producto.setId(1L); return producto; } } </code></pre> <p>ApplicationContext.xml:</p> <pre><code>&lt;context:component-scan base-package="es.gerardribas.example.controller"/&gt; &lt;bean id="xstreamMarshaller" class="org.springframework.oxm.xstream.XStreamMarshaller"/&gt; &lt;bean id="marshallingHttpMessageConverter" class="org.springframework.http.converter.xml.MarshallingHttpMessageConverter"&gt; &lt;property name="marshaller" ref="xstreamMarshaller"/&gt; &lt;property name="unmarshaller" ref="xstreamMarshaller"/&gt; &lt;/bean&gt; &lt;bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"&gt; &lt;property name="messageConverters"&gt; &lt;util:list id="beanList"&gt; &lt;ref bean="marshallingHttpMessageConverter"/&gt; &lt;/util:list&gt; &lt;/property&gt; &lt;/bean&gt; &lt;mvc:annotation-driven/&gt; </code></pre> <p>And web.xml:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"&gt; &lt;display-name&gt;restservice&lt;/display-name&gt; &lt;context-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;classpath:/applicationContext.xml&lt;/param-value&gt; &lt;/context-param&gt; &lt;listener&gt; &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt; &lt;/listener&gt; &lt;servlet&gt; &lt;servlet-name&gt;restservice&lt;/servlet-name&gt; &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt; &lt;init-param&gt; &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt; &lt;param-value&gt;&lt;/param-value&gt; &lt;/init-param&gt; &lt;/servlet&gt; &lt;servlet-mapping&gt; &lt;servlet-name&gt;restservice&lt;/servlet-name&gt; &lt;url-pattern&gt;/*&lt;/url-pattern&gt; &lt;/servlet-mapping&gt; &lt;/web-app&gt; </code></pre> <p>In Spring 3.0.3 runs but in 3.1.1 doesn't run.</p> <p>This is the console log:</p> <pre><code>11:44:50,527 DEBUG btpool0-0 servlet.DispatcherServlet:845 - DispatcherServlet with name 'restservice' determining Last-Modified value for [/restservice/products/1] 11:44:50,528 DEBUG btpool0-0 annotation.DefaultAnnotationHandlerMapping:266 - Matching patterns for request [/products/1] are [/products/{productId}] 11:44:50,528 DEBUG btpool0-0 annotation.DefaultAnnotationHandlerMapping:290 - URI Template variables for request [/products/1] are {productId=1} 11:44:50,528 DEBUG btpool0-0 annotation.DefaultAnnotationHandlerMapping:221 - Mapping [/products/1] to handler 'es.gerardribas.example.controller.impl.ProductControllerImpl@2ee7e5' 11:44:50,528 DEBUG btpool0-0 servlet.DispatcherServlet:861 - Last-Modified value for [/restservice/products/1] is: -1 11:44:50,529 DEBUG btpool0-0 servlet.DispatcherServlet:693 - DispatcherServlet with name 'restservice' processing GET request for [/restservice/products/1] 11:44:50,530 DEBUG btpool0-0 support.HandlerMethodInvoker:172 - Invoking request handler method: public es.gerardribas.example.common.domain.Product es.gerardribas.example.controller.impl.ProductControllerImpl.getProductById(java.lang.Long) 11:44:50,531 DEBUG btpool0-0 annotation.AnnotationMethodHandlerAdapter:942 - Written [es.gerardribas.example.common.domain.Product@e634bf] as "application/xhtml+xml" using [org.springframework.http.converter.xml.MarshallingHttpMessageConverter@43b5bb] 11:44:50,531 DEBUG btpool0-0 servlet.DispatcherServlet:808 - Null ModelAndView returned to DispatcherServlet with name 'restservice': assuming HandlerAdapter completed request handling 11:44:50,532 DEBUG btpool0-0 servlet.DispatcherServlet:674 - Successfully completed request </code></pre> <p>And this 3.1.1 doesn't run:</p> <pre><code>11:43:29,528 DEBUG btpool0-0 servlet.DispatcherServlet:819 - DispatcherServlet with name 'restservice' processing GET request for [/restservice/products/1] 11:43:29,528 DEBUG btpool0-0 annotation.RequestMappingHandlerMapping:213 - Looking up handler method for path /products/1 11:43:29,529 DEBUG btpool0-0 annotation.RequestMappingHandlerMapping:220 - Returning handler method [public es.gerardribas.example.common.domain.Product es.gerardribas.example.controller.impl.ProductControllerImpl.getProductById(java.lang.Long)] 11:43:29,530 DEBUG btpool0-0 support.DefaultListableBeanFactory:245 - Returning cached instance of singleton bean 'productControllerImpl' 11:43:29,530 DEBUG btpool0-0 servlet.DispatcherServlet:902 - Last-Modified value for [/restservice/products/1] is: -1 11:43:29,531 DEBUG btpool0-0 annotation.ExceptionHandlerExceptionResolver:132 - Resolving exception from handler [public es.gerardribas.example.common.domain.Product es.gerardribas.example.controller.impl.ProductControllerImpl.getProductById(java.lang.Long)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 11:43:29,531 DEBUG btpool0-0 annotation.ResponseStatusExceptionResolver:132 - Resolving exception from handler [public es.gerardribas.example.common.domain.Product es.gerardribas.example.controller.impl.ProductControllerImpl.getProductById(java.lang.Long)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 11:43:29,531 DEBUG btpool0-0 support.DefaultHandlerExceptionResolver:132 - Resolving exception from handler [public es.gerardribas.example.common.domain.Product es.gerardribas.example.controller.impl.ProductControllerImpl.getProductById(java.lang.Long)]: org.springframework.web.HttpMediaTypeNotAcceptableException: Could not find acceptable representation 11:43:29,532 DEBUG btpool0-0 servlet.DispatcherServlet:957 - Null ModelAndView returned to DispatcherServlet with name 'restservice': assuming HandlerAdapter completed request handling 11:43:29,532 DEBUG btpool0-0 servlet.DispatcherServlet:913 - Successfully completed request </code></pre> <p>Anyone knows that I am doing wrong?</p> <p>Thanks a lot!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload