Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting error message with spring "cvc-elt.1: Cannot find the declaration of element 'beans'."

I'm trying to set up a simple spring application and I'm getting the below exception. This is being run standalone in eclipse indigo.

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: Line 2 in XML document from class path resource [context.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
org.xml.sax.SAXParseException: cvc-elt.1: Cannot find the declaration of element 'beans'.
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:195)
      at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:131)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:384)
      at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:318)

Here's the initial portion of my code:

public static void main(String[] args) {

        try {

            BeanFactory beanfactory = new ClassPathXmlApplicationContext(
                    "context.xml");


            FirstBean bean = (FirstBean) beanfactory.getBean("show");

Here's my context.xml file:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" 
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
<bean id="anotherBean" class="AnotherBean" />
<bean id="show" class="FirstBean">
<constructor-arg ref="anotherBean" />
</bean>
<bean id="populateFD" class="PopulateFactData">
<constructor-arg value="localhost" />
<constructor-arg value="3309" />
</bean>
</beans>
like image 425
opike Avatar asked Apr 16 '12 22:04

opike


2 Answers

Are you sure you have spring-beans on the classpath?

This error normally means that it can't find a spring.schemas (which is in spring-beans.jar) explaining to it what that namespace means.

Other options are that the Maven Shade plugin has damaged spring.schemas, but that's unlikely to be the case as you haven't mentioned Maven.

like image 58
FauxFaux Avatar answered Nov 04 '22 21:11

FauxFaux


Maybe this post can help you:

Cannot find the declaration of element 'beans' in internet offline mode

It seems like being a problem of Schema configuration.

like image 1
Mik378 Avatar answered Nov 04 '22 21:11

Mik378