问题描述
谁能找出下面的命名空间声明有什么问题?我已经提到了所有的命名空间并给出了对架构文件的引用.不确定还缺少什么.
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>
错误信息:
在这一行找到多个注释:- cvc-complex-type.2.4.c:匹配的通配符是严格的,但找不到元素tx:annotation-driven"的声明.- schema_reference.4:无法读取架构文档'http://www.springframework.org/schema/tx/spring-tx.xsd',因为 1)找不到文件;2) 无法读取文件;3)文档的根元素不是 .
推荐答案
我更喜欢 STS 而不是 Eclipse,这是重现问题的方式...
I prefer STS over Eclipse and this is how one can reproduce the problem...
我有一个带有 Spring 上下文依赖项的 Maven 项目:
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>
当我现在在 src/main/resources
中创建 spring.xml
时,我遇到了同样的问题:
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>.
问题是,spring-tx
和 spring-context
不在依赖项中 - 添加后,错误已修复.
The problem is, that spring-tx
and spring-context
is not in dependencies - when added, error is fixed.
此答案中的更多详细信息.
这篇关于匹配通配符是严格的,但找不到元素 'tx:annotation-driven' 'context:component-scan' 的声明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!