Alex Rivera | Logout

maven spring - Cannot find the declaration of element 'beans'

Asked 2011-02-11T17:18:33.113
14

I have a spring project built with the usage of maven (packaged as jar) (dependencies are copied to a separate directory and added to classpath)

I want to run it as java -jar

The problem is that when I run it I get:

Caused by: org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.

It happens because spring.schemas and spring.handlers are located in a few jars i.e.: spring-beans, etc.

Is there any way to solve it, supposing that I don't want to use shade plugin to unpack all dependencies and concatenate the content of spring.schemas and spring.handlers?

I would also like to avoid saving xsd files in my project and changing schemaLocation to point to my location.

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">

    <camel:camelContext>
        <camel:routeBuilder ref="fakeRouteBuilder"/>
    </camel:camelContext>

    <bean id="fakeRouteBuilder" class="<className>" />


</beans>
Edit
Report

4 Answers

25

I know 2 situations where you can have this problem

  • If you don't have an internet connection (behind a proxy, for instance). In that case, download the XSD, copy it next to the XML, and change the schema location to xsi:schemaLocation=" http://www.springframework.org/schema/beans spring-beans-2.5.xsd ..."
  • If you have an internet connection / still have the problem, that's because you use different versions of Spring for the XSD and the jar.
answered 2011-03-24T15:38:26.227
2

Got the same problem because I was behind a proxy. I was running a Spring MVC app under Tomcat 6. Just added the following lines at the biginning of my catalina.bat file and that solved my problem:

set JAVA_OPTS=%JAVA_OPTS% -Dhttp.proxyHost=XXXX -Dhttp.proxyPort=YYYYY -Dhttp.proxyUser=ZZZZ -Dhttp.proxyPassword=XXXXXX
answered 2011-07-18T21:20:29.277
1

I was able to resolve a similar problem by clearing the xsd file from my remote resources cache, Window > Preferences > General > Network Connection > Cache

answered 2012-02-25T17:43:38.417
0

There's a http:// too much in your XSD declaration. Try this:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:camel="http://camel.apache.org/schema/spring"
    xsi:schemaLocation="
       http://www.springframework.org/schema/beans    
       http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://camel.apache.org/schema/spring
       http://camel.apache.org/schema/spring/camel-spring.xsd">

(yours was http://http://www.springframework.org/schema/beans/spring-beans-2.5.xsd)

answered 2011-02-11T21:44:49.180

Your Answer