Question

I am trying to implement Spring RestTemplate into my exsting Spring REST Web application. 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. Does it enough to add just one dependency for RestTemplate I added that but I get error:

<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
Was it helpful?

Solution

Looks like org.springframework.web 3.0.0.M1 imports old version of spring-beans JAR and overrides the newer one. 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?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top