The corresponding template is strict, but no declaration was found for the element 'tx: annotation-driven' 'context: component-scan.

Can anyone determine what is wrong with the namespace declaration below? I mentioned all namespaces and gave links to schema files. Not sure what is missing yet.

<?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" xmlns:tx="http://www.springframework.org/schema/tx" 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/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <context:component-scan base-package="com.mypackage" /> <context:annotation-config /> <tx:annotation-driven /> </beans> 

Error message:

A few annotations found on this line: - cvc-complex-type.2.4.c: The corresponding template is strict, but no declaration was found for the element 'tx: annotation-driven'. - schema_reference.4: Failed to read the schema document http://www.springframework.org/schema/tx/spring-tx.xsd ', because 1) the document could not be found; 2) the document cannot be read; 3) the root element of the document is not <xsd:schema> .

+1
java spring xml xsd
Jan 14 '16 at 0:19
source share
1 answer

I prefer STS over Eclipse, and here's how to reproduce the problem ...

I have a Maven project with a Spring context dependency:

pom.xml

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>betlista</groupId> <artifactId>tests.so.q34779551</artifactId> <version>0.0.1-SNAPSHOT</version> <name>SO-q34779551</name> <dependencies> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>4.2.4.RELEASE</version> </dependency> </dependencies> </project> 

When I now create spring.xml in src/main/resources just like yours, I have the same problems:

 schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/beans/spring-beans.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/context/spring-context.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/tx/spring-tx.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root element of the document is not <xsd:schema>. 

The problem is that spring-tx and spring-context not in dependencies - a bug has been fixed when adding.

See more in this answer .

+1
Jan 14 '16 at 12:03
source share



All Articles