简体   繁体   English

Spring RestTemplate依赖错误

[英]Spring RestTemplate Dependency Error

I am trying to implement Spring RestTemplate into my exsting Spring REST Web application. 我正在尝试在现有的Spring REST Web应用程序中实现Spring RestTemplate。 I tried that: 我尝试过:

...
private final String BASE_URL = "http://localhost:8080/a";
private final RestTemplate restTemplate = new RestTemplate();
...
Map<String, String> x = new HashMap<String, String>();
x.put("hotel", "42");
x.put("booking", "21");
String result = restTemplate.getForObject(BASE_URL + "/y/2", String.class, x);

I am using 3.0.5.RELEASE as my Spring version. 我正在使用3.0.5.RELEASE作为我的Spring版本。 Does it enough to add just one dependency for RestTemplate I added that but I get error: 是否足以为我添加的RestTemplate仅添加一个依赖项,但出现错误:

<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>org.springframework.web</artifactId>
   <version>3.0.0.M1</version>
</dependency>

My application works however after I add just that dependency I get that error: 我的应用程序正常工作,但是仅添加该依赖项后,我得到该错误:

[2011-11-10 22:01:25,400][WARN ] [org.springframework.security.core.SpringSecurityCoreVersion] - [You are advised to use Spring 3.0.3 or later with this version. You are running: 3.0.0.M4]
Nov 10, 2011 10:01:25 PM org.apache.catalina.core.StandardContext startInternal
SEVERE: Error listenerStart
[2011-11-10 22:01:25,467][ERROR] [org.springframework.web.context.ContextLoader] - [Context initialization failed]
org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML document from ServletContext resource [/WEB-INF/security-appl-context.xml]; nested exception is java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.getLocalName(Lorg/w3c/dom/Node;)Ljava/lang/String;
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:394) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:316) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:284) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:143) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:178) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:149) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:125) ~[org.springframework.web-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.web.context.support.XmlWebApplicationContext.loadBeanDefinitions(XmlWebApplicationContext.java:93) ~[org.springframework.web-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:127) ~[org.springframework.context-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:425) ~[org.springframework.context-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:355) ~[org.springframework.context-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.web.context.ContextLoader.createWebApplicationContext(ContextLoader.java:270) ~[org.springframework.web-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.web.context.ContextLoader.initWebApplicationContext(ContextLoader.java:197) ~[org.springframework.web-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.web.context.ContextLoaderListener.contextInitialized(ContextLoaderListener.java:47) [org.springframework.web-3.0.0.M4.jar:3.0.0.M4]
    at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:4681) [catalina.jar:7.0.11]
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5184) [catalina.jar:7.0.11]
    at org.apache.catalina.core.StandardContext$1.call(StandardContext.java:5179) [catalina.jar:7.0.11]
    at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334) [na:1.6.0_23]
    at java.util.concurrent.FutureTask.run(FutureTask.java:166) [na:1.6.0_23]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [na:1.6.0_23]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [na:1.6.0_23]
    at java.lang.Thread.run(Thread.java:679) [na:1.6.0_23]
Caused by: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.getLocalName(Lorg/w3c/dom/Node;)Ljava/lang/String;
    at org.springframework.security.config.SecurityNamespaceHandler.parse(SecurityNamespaceHandler.java:70) ~[spring-security-config-3.0.5.RELEASE.jar:3.0.5.RELEASE]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1327) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.parseCustomElement(BeanDefinitionParserDelegate.java:1317) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.parseBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:135) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.DefaultBeanDefinitionDocumentReader.registerBeanDefinitions(DefaultBeanDefinitionDocumentReader.java:92) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.registerBeanDefinitions(XmlBeanDefinitionReader.java:475) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.doLoadBeanDefinitions(XmlBeanDefinitionReader.java:372) ~[org.springframework.beans-3.0.0.M4.jar:3.0.0.M4]
    ... 21 common frames omitted

Looks like org.springframework.web 3.0.0.M1 imports old version of spring-beans JAR and overrides the newer one. 看起来像org.springframework.web 3.0.0.M1导入了旧版本的spring-beans JAR,并覆盖了较新的版本。 Try adding: 尝试添加:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>org.springframework.web</artifactId>
    <version>3.0.0.M1</version>
    <exclusion>
        <groupId>org.springframework</groupId>
        <artifactId>org.springframework.beans</artifactId>
    </exclusion>
</dependency>

Or better, why aren't you using org.springframework.web in 3.0.5.RELEASE version like the rest of your project? 或者更好的是,为什么不像其他项目一样在3.0.5.RELEASE版本中使用org.springframework.web

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 具有rootUri返回URI的Spring RestTemplate不是绝对错误 - Spring RestTemplate with rootUri return URI is not absolute error 春天resttemplate - Spring resttemplate 春季-调用https REST服务的RestTemplate错误(证书错误) - Spring - RestTemplate Error calling a https rest service (Certificate error) 使用授权标头发送时,Spring RestTemplate 会出现 401 Unauthorized 错误 - Spring RestTemplate gives 401 Unauthorized error when sending with Authorization Header RestTemplate 请求发生错误 Header 对于 spring 4.1.3 太大 - Error occured in RestTemplate Request Header too large for spring 4.1.3 使用 resttemplate 从 spring-boot 中的 Graph API 获取图像时出错 - Error in getting image from Graph API in spring-boot with resttemplate 带有参数的Spring RestTemplate HTTP Post导致400错误的请求错误 - Spring RestTemplate HTTP Post with parameters cause 400 bad request error 错误401未经授权-Spring RestTemplate OAuth2.0 - Error 401 Unauthorized - Spring RestTemplate OAuth2.0 使用Spring Boot RestTemplate解析嵌套元素会产生JSON解析错误 - Parsing nested elements with Spring Boot RestTemplate gives JSON parse error Spring restTemplate.getForObject()的JSON转换错误 - JSON conversion error from Spring restTemplate.getForObject()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM