【问题标题】:cvc-elt.1: Cannot find the declaration of element 'beans' - Spring 4.0.2 [duplicate]cvc-elt.1:找不到元素“beans”的声明-Spring 4.0.2 [重复]
【发布时间】:2015-04-30 09:01:32
【问题描述】:

虽然我尝试了很多方法来解决这个问题,但还没有成功。

我在“dispatcher-servlet.xml”文件中收到此错误“cvc-elt.1: 找不到元素 'beans' 的声明”。

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:beans="http://www.springframework.org/schema/beans"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <context:component-scan base-package="com.b2b.controller" />

</beans>

我的 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>com.b2b</groupId>
    <artifactId>b2b</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>b2b</name>
    <description>Blog to Blog</description>

    <!-- Plugin needs to be added in the project so that these will be available with the war file for ever. -->
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <version>2.2</version>
            </plugin>

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>

        </plugins>
    </build>

    <!-- Dependencies Version -->
    <properties>
        <springframework.version>4.0.2.RELEASE</springframework.version>
        <javax.servlet.version>3.1.0</javax.servlet.version>
        <commons.logging.version>1.2</commons.logging.version>
        <hibernate-validator>5.1.3.Final</hibernate-validator>
        <aspectj.version>1.7.4</aspectj.version>
    </properties>


    <dependencies>
        <!-- Spring base dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-beans</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-expression</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- Spring Other dependencies -->
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-web</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aop</artifactId>
            <version>${springframework.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${springframework.version}</version>
        </dependency>

        <!-- Javax Http Servlet Dependency -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>${javax.servlet.version}</version>
            <scope>provided</scope>
        </dependency>

        <!-- Commons Logging -->
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>${commons.logging.version}</version>
        </dependency>

        <!-- Hibernate Validator -->
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-validator</artifactId>
            <version>${hibernate-validator}</version>
        </dependency>

        <!-- Aspectj Dependency -->
        <dependency>
            <groupId>org.aspectj</groupId>
            <artifactId>aspectjweaver</artifactId>
            <version>${aspectj.version}</version>
        </dependency>

    </dependencies>

</project>

谁能看看我的问题。

【问题讨论】:

  • 尝试禁用语言服务器错误:进入首选项 -> 语言服务器并将它们全部关闭。

标签: spring tomcat


【解决方案1】:

您为 beans 元素使用了不带前缀的名称,但您已将相关的命名空间绑定到前缀

xmlns:beans="http://www.springframework.org/schema/beans"

您可能希望使用默认命名空间声明 xmlns="..." 而不是 xmlns:beans="...",或者替代方法是为元素名称添加前缀

<beans:beans ...>

【讨论】:

    【解决方案2】:

    xmlns:beans="http://www.springframework.org/schema/beans" 更改为xmlns="http://www.springframework.org/schema/beans"

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
        xmlns="http://www.springframework.org/schema/beans"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
            http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd">
    
        <context:component-scan base-package="com.b2b.controller" />
    
    </beans>
    

    【讨论】:

      猜你喜欢
      • 2015-02-09
      • 2015-12-19
      • 1970-01-01
      • 1970-01-01
      • 2017-02-05
      • 2020-05-08
      • 2015-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多