任何人都可以识别下面的命名空间声明有什么问题吗?我已经提到了所有命名空间,并提供了对模式文件的引用。不确定还缺少什么。
<?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>
错误讯息:
此行找到多个注释: - cvc-complex-type.2.4.c:匹配的通配符是严格的,但是没有找到元素&t; tx:annotation-driven&#39;的声明。 - schema_reference.4:无法读取架构文档&#39; http://www.springframework.org/schema/tx/spring-tx.xsd&#39;,因为1) 找不到文件; 2)文件无法阅读; 3) 文档的根元素不是
<xsd:schema>
。
答案 0 :(得分:1)
我更喜欢STS而不是Eclipse,这就是人们如何重现这个问题......
我有一个带有Spring上下文依赖的Maven项目:
<强>的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>
当我现在在spring.xml
创建src/main/resources
时,我遇到同样的问题:
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>.
问题是,spring-tx
和spring-context
不在依赖关系中 - 添加时,错误是固定的。
this answer中的更多详情。