gpt4 book ai didi

java - 匹配通配符严格,但找不到元素 'tx:annotation-driven' 'context:component-scan' 的声明

转载 作者:行者123 更新时间:2023-11-30 07:40:22 24 4
gpt4 key购买 nike

任何人都可以确定下面的命名空间声明有什么问题吗?我已经提到了所有 namespace 并提供了对架构文件的引用。不确定还缺少什么。

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

错误消息:

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>.

最佳答案

与 Eclipse 相比,我更喜欢 STS,这就是重现问题的方法...

我有一个带有 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>

当我现在在 src/main/resources 中创建 spring.xml 时,与您的相同,我遇到了同样的问题:

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-txspring-context 不在依赖项中 - 添加后,错误已修复。

更多详细信息请参见this answer .

关于java - 匹配通配符严格,但找不到元素 'tx:annotation-driven' 'context:component-scan' 的声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34779551/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com