No ads found for item context: scan component '

I start with Spring 3 (3.1.2) and the Google App Engine.

I followed the tutoria online, now I have my bean-implemented xml that has a problem on startup.

this is code

<?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:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context/ http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="my.example"> 

where the root package of the entire java file is "my.example". A subpackage is a β€œmodel” and a β€œcontroller” with subpackages. Now.

when I run the application, I return this error:

 org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException: Line 10 in XML document from ServletContext resource [/WEB-INF/spring-servlet.xml] is invalid; nested exception is org.xml.sax.SAXParseException: cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'context:component-scan'. 

with lots of stacktrace.

Does anyone know how I can solve this? I checked the XSD and they seem to be correct.

+4
source share
3 answers

You are probably missing spring -context.jar, i.e. the one that contains the definition for the context schema.

+1
source

I don't know if this helps, but I had a bug very similar to yours when using the maven shade plugin to make one .jar, and the shadow plugin destroyed the spring.handlers and spring.schemas from META-INF/ .

This SO answer pointed me in the right direction: fooobar.com/questions/340525 / ...

And the document on using AppendingTransformer to add these spring bits back to your META-INF/ folder helped: http://maven.apache.org/plugins/maven-shade-plugin/examples/resource-transformers.html#AppendingTransformer

+1
source

The problem is incompatible schema locations with your spring -context dependencies.

Replace

 http://www.springframework.org/schema/context/spring-context.xsd 

 http://www.springframework.org/schema/context/spring-context-2.5.xsd 

That should do the trick! I used spring -context 3.1.1 and I was getting the same error regarding http://www.springframework.org/schema/context/spring-context-2.1.xsd

However, you should also use the maven tree dependency and check if you have different versions of spring. This error may also be related to this fact ...

+1
source

Source: https://habr.com/ru/post/955411/


All Articles