java – Restful webservice调用中的Spring错误
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了java – Restful webservice调用中的Spring错误,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3143字,纯文字阅读大概需要5分钟。
内容图文
当我尝试使用restful webservice访问rezgo sample 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总是选择错误的(较旧的)并且我得到这样的错误.确保您的环境中没有任何弹簧核心3.0或更早版本.
内容总结
以上是互联网集市为您收集整理的java – Restful webservice调用中的Spring错误全部内容,希望文章能够帮你解决java – Restful webservice调用中的Spring错误所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。