Wildcard matching is comprehensive, but the declaration of element XXXXX' could not be found

Problem : When configuring Spring, such a frequent error as the title is prone to occur. The error is as follows (take context as an example)

org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException:
Line 8 in XML document from class path resource [applicationContext.xml] is invalid; 
nested exception is org.xml.sax.SAXParseException;
lineNumber: 8; columnNumber: 47; cvc-complex-type.2.4.c: 
Wildcard matching is comprehensive, but the declaration of element 'context:component-scan' could not be found.

 

Look again at the constraints of beans:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
    >

Huh? Isn't this a declaration with context?

That's right, but there is something missing, that is   the update of the xsi:schemaLocation of the context's xsi schema address

  1. xmlns: The full name is xml namespace, that is, the namespace is specified for the current xml.

  2. xmlns:xsi : refers to the tag specification to be followed by the current xml.

  3. As above , xmlns with hdp, xsi, aop, cache, context, mvc... is a tag to be used by the current xml, followed by the specification to be followed by the specified tag.

  4. xsi:schemaLocation: The verification file corresponding to the specified namespace is used to define the address of the xml schema, that is, the syntax that needs to be followed when writing xml, and is used to declare the schema document of the target namespace. . It consists of two parts. The first part is the name of the namespace, and the latter is the address of the xsd (xmlschema) document, which means that the schema file that defines the namespace is referenced, so that tools such as eclipse can parse and verify your xml. Whether the file conforms to the syntax specification. Simply put, a schema document that declares the target namespace .

 

Solution : In addition to adding xmlns:XXX, you also need to add the corresponding xsi:schemaLocation [you can google the required xsi:schemaLocation ]

as follows:

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context" 
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
                        http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
                        http://www.springframework.org/schema/context 
                        http://www.springframework.org/schema/context/spring-context.xsd"
    >

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325065275&siteId=291194637