今天配置完:
~~~
<!-- 自動掃描與裝配,包含子包 -->
<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中各種版本,如果沒有的話,會自動使用最新版本。
- 前言
- Spring簡化配置
- Spring中使用AspectJ實現AOP
- Spring中JDK的動態代理和CGLIB代理的區別
- Spring配置問題——元素 "context:component-scan" 的前綴 "context" 未綁定
- Hibernate中編程式事物的簡單使用
- 使用Spring為Hibernate配置聲明式事物
- Struts2+AJAX獲取json數據
- 中間件概述
- EJB(Enterprise Java Bean)概述
- JBoss 6.1安裝配置問題
- EJB對象的部署及客戶端調用簡單示例
- 有狀態的EJB對象和無狀態的EJB對象
- EJB遠程調用和本地調用
- MyBatis——入門select