java - Restful web服务调用中的Spring错误

标签 java web-services spring

当我尝试使用 restful web 服务访问 rezgo 示例 api 时,出现异常。我想在示例对象中转换此响应

package com.mycompany.hr.client;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.client.RestOperations;
import org.springframework.web.client.RestTemplate;
import org.springframework.ws.client.core.WebServiceTemplate;
public class Main {

    public static void main(String[] args) throws Exception {

        List<MediaType> acceptableMediaTypes = new ArrayList<MediaType>();
          acceptableMediaTypes.add(MediaType.APPLICATION_XML);
          HttpHeaders headers = new HttpHeaders();
          headers.setAccept(acceptableMediaTypes);
          //ResponseEntity<String> result = restTemplate.exchange("http://localhost:8080/spring-rest-provider/krams/person/{id}", HttpMethod.PUT, entity, String.class, id);
          Map<String,String> urlParam=new HashMap<String,String>();
          urlParam.put("key","2D8-F3V0-X7C0-C6I");
          urlParam.put("transcode", "p103");
          urlParam.put("i", "p103");
          urlParam.put("t", "tag");
          urlParam.put("q", "nature");

          RestTemplate wsTemplate = new RestTemplate();
         ResponseEntity<TourList> tl=( wsTemplate).getForEntity("http://xml.rezgo.com/xml?key=2D8-F3V0-X7C0-C6I&transcode=p103&i=search_items&t=tag&q=nature",TourList.class,Collections.singleton(urlParam));

    }

}

这是我遇到异常的代码。

Exception in thread "main" java.lang.NoSuchMethodError: org.springframework.util.CollectionUtils.unmodifiableMultiValueMap(Lorg/springframework/util/MultiValueMap;)Lorg/springframework/util/MultiValueMap;
    at org.springframework.web.util.UriComponents.<init>(UriComponents.java:100)
    at org.springframework.web.util.UriComponentsBuilder.build(UriComponentsBuilder.java:222)
    at org.springframework.web.util.UriComponentsBuilder.build(UriComponentsBuilder.java:212)
    at org.springframework.web.util.UriTemplate.<init>(UriTemplate.java:70)
    at org.springframework.web.client.RestTemplate$HttpUrlTemplate.<init>(RestTemplate.java:653)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:407)
    at org.springframework.web.client.RestTemplate.getForEntity(RestTemplate.java:229)
    at com.mycompany.hr.client.Main.main(Main.java:52)

请帮我解决这个问题。

最佳答案

CollectionUtils.unmodifiableMultiValueMap 是在Spring 3.1中加入的,但在早期版本中没有出现。听起来您正在使用 spring-core 3.1 构建您的应用程序,但您的运行时环境使用的是早期版本。

也许您最近升级了 Spring,并且在某处有一个陈旧的 lib 目录,其中包含多个版本的 spring-core?根据我的经验,Java 似乎总是选择错误的(较旧的)并且我会遇到这样的错误。确保您的环境中的任何地方都没有 spring-core 3.0 或更早版本。

关于java - Restful web服务调用中的Spring错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13091593/

相关文章:

c# - Web 引用中断 SSIS 包

java - Spring AMQP - 使用带 TTL 的死信机制进行消息重新排队

java - 如何为 java spring maven 应用程序映射域?

java - 无法找到 JAX-WS 架构 http ://jax-ws. dev.java.net/spring/servlet.xsd

c# - 使用 C# Web 服务将图像从 Android 应用程序上传到服务器

java - 事务管理器和实体管理器有什么区别

java - 如何从 Java Web 应用程序托管用户生成的 HTML 页面?

构建 NativeScript 项目时出现 java.util.zip.zipException

java - 绑定(bind)抛出异常

Java多线程通信,生产者-消费者-取消,四个线程交互。任何干净稳健的方法都可以做到这一点