1. 程式人生 > >Spring配置問題——元素 "context:component-scan" 的字首 "context" 未繫結

Spring配置問題——元素 "context:component-scan" 的字首 "context" 未繫結

            今天配置完:

<!-- 自動掃描與裝配,包含子包 -->
	<context:component-scan base-package="cn.itcast.oa"></context:component-scan>

        這句話之後,validating 我的spring配置檔案就一直走不下去了。當時以為是myeclipse卡了,之後去掉了所有的validating。

         後來寫了個單元測試測試Spring配置的時候,發現報錯:

         columnNumber:54; 元素 "context:component-scan" 的字首 "context" 未繫結。

          看來果然是自動裝配與掃描有問題。查了下,貌似是少了context的名稱空間的問題:

      <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tx="http://www.springframework.org/schema/tx"
    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/context  
                http://www.springframework.org/schema/context/spring-context-2.5.xsd


            ">

    加上帶紅色字型的部分,成功run過去了。

     順便說下xml中各種版本,如果沒有的話,會自動使用最新版本。