Announcement Announcement Module
No announcement yet.
Getting NoSuchMethodError with RestTemplate in Spring MVC+SWF client app Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Getting NoSuchMethodError with RestTemplate in Spring MVC+SWF client app


    Im a newbie to Spring. Im trying to build a client app which can consume Restful services from our internal API's to populate data in the client. (The API's are RESTful CXF JAX-RS in nature)

    Im using the booking-mvc sample from Spring downloads and Im working off on this. Everything was working fine until I switched the datasource from using some test data to web api response.

    I read about RestTemplate support in Spring 3.0 and thought this might be the solution.Unfortunately, I have hit a dead-end and Im unable to figure out if Im looking at the right technologies to use or if Im doing something drastically wrong.

    Im just trying to get RestTemplate to work with a static xml file at : /WEB-INF/hotels/test.xml file.

    Im trying to implement the code from this tutorial :

    I dont get any compile time errors , but when I run the app from Tomcat and hit the url that directs to the controller which in turn uses the RestTemplate instantiation, I get the following error:

    SEVERE: Servlet.service() for servlet Spring MVC Dispatcher Servlet threw exception
    java.lang.NoSuchMethodError: org.springframework.oxm.Unmarshaller.supports(Ljav a/lang/ClassZ
    at org.springframework.http.converter.xml.Marshalling HttpMessageConverter.supports(MarshallingHttpMessa
    at org.springframework.http.converter.AbstractHttpMes sageConverter.canRead(AbstractHttpMessageConverter .java:97)
    at org.springframework.web.client.RestTemplate$Accept HeaderRequestCallback.doWithRequest(RestTemplate.j ava:506)
    at org.springframework.web.client.RestTemplate.doExec ute(
    at org.springframework.web.client.RestTemplate.execut e(
    at org.springframework.web.client.RestTemplate.getFor Object(
    at kingService.findProgramDetailsById(JpaBookingServi
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at npointUsingReflection(
    at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(
    at $Proxy14.findProgramDetailsById(Unknown Source)
    at Controller.pshow(
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Native
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(De
    at java.lang.reflect.Method.invoke(
    at ndlerMethodInvoker.invokeHandlerMethod(HandlerMeth
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.invokeHandlerMethod(An
    at org.springframework.web.servlet.mvc.annotation.Ann otationMethodHandlerAdapter.handle(AnnotationMetho
    at org.springframework.web.servlet.DispatcherServlet. doDispatch(
    at org.springframework.web.servlet.DispatcherServlet. doService(
    at org.springframework.web.servlet.FrameworkServlet.p rocessRequest(
    at org.springframework.web.servlet.FrameworkServlet.d oGet(
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:575)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:668)
    at ternalDoFilter(
    at Filter(
    at$ VirtualFilterChain.doFilter( 343)
    at FilterSecurityInterceptor.invoke(FilterSecurityInt
    at FilterSecurityInterceptor.doFilter(FilterSecurityI
    at$ VirtualFilterChain.doFilter( 355)
    at ranslationFilter.doFilter(ExceptionTranslationFilt
    at$ VirtualFilterChain.doFilter( 355)
    at nagementFilter.doFilter(SessionManagementFilter.ja va:100)
    at$ VirtualFilterChain.doFilter( 355)
    at onymousAuthenticationFilter.doFilter(AnonymousAuth
    at$ VirtualFilterChain.doFilter( 355)
    at tyContextHolderAwareRequestFilter.doFilter(Securit
    at$ VirtualFilterChain.doFilter( 355)
    at estCacheAwareFilter.doFilter(RequestCacheAwareFilt
    at$ VirtualFilterChain.doFilter( 355)
    at$ VirtualFilterChain.doFilter( 355)
    at stractAuthenticationProcessingFilter.doFilter(Abst
    at$ VirtualFilterChain.doFilter( 355)
    at gout.LogoutFilter.doFilter(
    at$ VirtualFilterChain.doFilter( 355)
    at ontextPersistenceFilter.doFilter(SecurityContextPe
    at$ VirtualFilterChain.doFilter( 355)
    at doFilter(
    at org.springframework.web.filter.DelegatingFilterPro xy.invokeDelegate(
    at org.springframework.web.filter.DelegatingFilterPro xy.doFilter(
    at ternalDoFilter(
    at Filter(
    at org.springframework.web.filter.HiddenHttpMethodFil ter.doFilterInternal( 7)
    at org.springframework.web.filter.OncePerRequestFilte r.doFilter(
    at ternalDoFilter(
    at Filter(
    at org.apache.catalina.core.StandardWrapperValve.invo ke(
    at org.apache.catalina.core.StandardContextValve.invo ke(
    at org.apache.catalina.core.StandardHostValve.invoke(
    at org.apache.catalina.valves.ErrorReportValve.invoke (
    at org.apache.catalina.core.StandardEngineValve.invok e(
    at org.apache.catalina.connector.CoyoteAdapter.servic e(
    at org.apache.coyote.http11.Http11Processor.process(H
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.process(

    I would greatly appreciate any help or advice on what technologies/libraries to use to consume CXF JAX-RS services which are outside of my stand alone client app. Is this possible using RestTemplate , if so , please let me know what is the right way to integrate this into my app.

    Thanks in advance

  • #2
    Please use [ code][/code ] tags when posting code.

    You are either mixing spring versions or you have spring in different class loaders... Judging by the stack trace you are mixing versions.


    • #3
      Sorry about that, I wasnt sure what formatting was required. Thanks for the tip

      I did notice that I was including some spring 3.0.5 jars in my tomcat classpath for older projects, I went ahead and removed those.
      But, I still get the same error and the same stack trace.(I did a text compare and found no stark difference)

      My application class path has the following jars which were downloaded using maven.

      I also see maven downloaded ( Im not sure if xstream plays along well with this)

      The rest of the application however, runs just fine until the controller switches to the method where I have implemented the RestTemplate code. I am using XStream library for marshalling.

      Here's the code fragment:

      ApplicationContext applicationContext = new ClassPathXmlApplicationContext("appContext.xml",
      RestTemplate restTemplate = applicationContext.getBean("restTemplate", RestTemplate.class);
      try {
      	    // retrieve a particular customer
      	    String url = "http://localhost:8080/hotels/test.xml";
      	    List<Customer> customers = (List) restTemplate.getForObject(url, List.class);
      	    for (Customer customer : customers) {
      		System.out.println("customer - id:" + customer.getId() + ", name:" + customer.getName());
      The project uses a static file (test.xml) which is a list of customers with id and name tags. There is a Customer class. I have configured the restTemplate bean in the appContext.xml

      Please let me know if this is still an issue with project set-up or if it has to specifically with the method implementing restTemplate.


      • #4
        After talking to my team, they said they had trouble unmarshalling with xstream library and suggested that I use jaxb.
        After making the changes in the code and reading sample tutorials for implementing Jaxb2Marshaller, Im able to get restTemplate to work in my project.

        Thank you for helping out but it would be great to know why the above error was thrown, so I can get a complete understanding of the scenario. Im still completely new to Spring and still trying the ropes. So, Im sure I might have missed something in the above experiment.