1

Can anyone identify what is wrong with the namespace declaration below? I've mentioned all the namespaces and gave references to the schema files. Not sure what else is missing.

<?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:

Multiple annotations found at this line: - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'tx:annotation-driven'. - 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>.

kjhughes
  • 106,133
  • 27
  • 181
  • 240
RKodakandla
  • 3,318
  • 13
  • 59
  • 79
  • 2
    sounds like an eclipse issue – guido Jan 14 '16 at 00:24
  • This would happen if you cannot access the mentioned [spring-tx.xsd](http://www.springframework.org/schema/tx/spring-tx.xsd). Test your access by bringing it up in a web browser. I can access that XSD, and your XML does validate successfully for me. – kjhughes Jan 14 '16 at 00:33
  • If that's not it, note also that there have been [cases where conflicting versions of Spring jars have resulted in errors resembling XSD access errors](http://stackoverflow.com/a/29472455/290085). – kjhughes Jan 14 '16 at 02:05
  • @kjhughes.. thanks. I tried your suggestion but it didn't help. I'm able to access the XSDs also. I finally gave up and just turned off XML validation. – RKodakandla Jan 14 '16 at 13:40

2 Answers2

1

I prefer STS over Eclipse and this is how one can 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 same as yours I have 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 is not in dependencies - when added, error is fixed.

More details in this answer.

Community
  • 1
  • 1
Betlista
  • 10,327
  • 13
  • 69
  • 110
  • but I do have the tx and context jars in my project dependency. Application works fine when deployed to websphere on RAD. It is just RAD (Eclipse) complaining.. – RKodakandla Jan 14 '16 at 13:39
  • It might be a lot of things in Eclipse, proxy for example... You can als check [this answer](http://stackoverflow.com/a/1075043/384674) for a local schema versions... – Betlista Jan 14 '16 at 13:47
0

I was getting the same error when I created Spring MVC project using Maven which automatically adds core dependencies but sometime build doesn't get successful, in that case if you will enable Annotated component scan it will give the above error.

Solution : Just update Spring Core Dependencies in Pom.xml by adding below tag according to your Spring version.

<dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-core</artifactId>
        <version>5.2.4.RELEASE</version>
Ratnesh K
  • 19
  • 6