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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With