Java – use spring to get the declaration of the error message “CVC ELT. 1: element” bean “not found
•
Java
I tried to set up a simple spring application and I got the following exception This is indigo running independently during the solar eclipse
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 is the initial part of my code:
public static void main(String[] args) { try { beanfactory beanfactory = new ClassPathXmlApplicationContext( "context.xml"); FirstBean bean = (FirstBean) beanfactory.getBean("show");
This is 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>
Solution
Are you sure you have spring beans on the classpath?
This error usually means that it cannot find a spring Schemas (in spring - beans. Jar) to explain what this namespace means
The other option is that the Maven shade plug-in has damaged spring Schemas, but it's unlikely because you didn't mention Maven
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码