【问题标题】:The prefix "context" for element "context:component-scan" is not bound元素“context:component-scan”的前缀“context”未绑定
【发布时间】:2011-10-31 04:22:31
【问题描述】:

我正在研究 spring3 mvc 并提出了这个错误

org.xml.sax.SAXParseException:元素“context:component-scan”的前缀“context”未绑定。

这是我的调度程序 servlet

<?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:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <mvc:annotation-driven />

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

【问题讨论】:

    标签: xml spring


    【解决方案1】:

    当您缺少 xmlns:context 声明但您已声明它时,就会出现这种类型的错误。检查"com.web" 包中的类是否有任何错误编码。

    【讨论】:

    • 我有同样的错误,但我已经声明了xmlns:context并且base-package没有错误,你知道这个错误的其他原因吗? +1 回答您的问题,例如第三人 :)
    • nvm,原来我打错了:)
    【解决方案2】:

    有时问题在于忘记添加命名空间。您应该在创建配置文件的向导或创建后的名称空间选项卡中执行此操作。选择合适的命名空间,在这种情况下应该是上下文,然后保存。

    【讨论】:

      【解决方案3】:

      在 dispatcher-servlet.xml 文件本身的 beans 中添加以下内容:

      所以你的文件看起来像:

      <?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:p="http://www.springframework.org/schema/p"
      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-2.5.xsd
       http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
       http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
       http://www.springframework.org/schema/jdbc http://www.springframework.org/schema/jdbc/spring-jdbc-4.0.xsd
       http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-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.Project_name.Controller"></context:component-scan>
      </beans>
      

      【讨论】:

        【解决方案4】:

        您可能会丢失此个人资料:xmlns:context="http://www.springframework.org/schema/context"。 请写出来。

        【讨论】:

          【解决方案5】:

          当你创建 spring-configuration.xml 文件时,你可以按照这些步骤操作。输入名称后点击“下一步”,现在有很多可用的复选框,你可以选择'bean','mvc','context', 'p'.no need to select downstairs shows some checkbox.because it will select default settings which is your eclipse/spring support.

          谢谢,

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 2012-02-25
            • 2013-01-14
            • 2015-01-29
            • 2011-08-10
            • 2012-10-03
            • 1970-01-01
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多