Java 如何在Servlet中使用SpringRESTTemplate?
我正在尝试在Servlet项目中使用RestTemplate。我有一些值要发送到RESTfulWeb服务。我尝试了以下代码:Java 如何在Servlet中使用SpringRESTTemplate?,java,spring,spring-mvc,servlets,jakarta-ee,Java,Spring,Spring Mvc,Servlets,Jakarta Ee,我正在尝试在Servlet项目中使用RestTemplate。我有一些值要发送到RESTfulWeb服务。我尝试了以下代码: RestTemplate restTemplate = new RestTemplate(); String url = "http://localhost:8080/spring-rest/data/putdata{id}{name}"; Map<String, String> map = new HashMap<String, String>
RestTemplate restTemplate = new RestTemplate();
String url = "http://localhost:8080/spring-rest/data/putdata{id}{name}";
Map<String, String> map = new HashMap<String, String>();
map.put("id", "100");
map.put("name", "Ram");
Address address = new Address("Dhananjaypur", "Varanasi","UP");
restTemplate.put(url, address, map);
但是我已经在类路径中添加了jar文件。有人能帮我吗?肯定在那里,你确定你的回购中有这个罐子,并且你在使用它吗 spring-web-4.3.9-RELEASE.jar而不是spring-web-4.39-RELEASE.jar
$ jar tvf spring-web-4.3.9.RELEASE.jar | grep RestTemplate.class
30116 Wed Jun 07 19:11:32 BST 2017 org/springframework/web/client/RestTemplate.class
-从2012年开始,我已经正确添加了jar文件,给出了异常
$ jar tvf spring-web-4.3.9.RELEASE.jar | grep RestTemplate.class
30116 Wed Jun 07 19:11:32 BST 2017 org/springframework/web/client/RestTemplate.class