我正在尝试将Spring RestTemplate实现到我的exsting Spring REST Web应用程序中。 我试过了:
...
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);
我使用3.0.5.RELEASE
作为我的Spring版本。是否足以为RestTemplate添加一个依赖项我添加了但是我收到错误:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>org.springframework.web</artifactId>
<version>3.0.0.M1</version>
</dependency>
我的应用程序工作但是在我添加该依赖项之后我得到了该错误:
[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
答案 0 :(得分:0)
看起来org.springframework.web
3.0.0.M1导入spring-beans
JAR的旧版本并覆盖较新版本。尝试添加:
<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>
或者更好的是,为什么不在3.0.5.RELEASE版本中使用org.springframework.web
,就像项目的其余部分一样?