配置xml時一些jar和命名空間問題,如mvc:annotation-driven

暑假用springmvc搭了一些小demo,剛開始和以前搭建ssh一樣,出現了一些jar未加載和xml文件的命名空間沒引入的問題。想想每次都是出了問題去網上百度,有點煩,就記下來了。

Q1.元素 "mvc:annotation-driven" 的前綴 "mvc"未綁定

辦法:這是我在spring-servlet.xml文件裏使用<mvc>開頭的標籤時,忘記引入了命名空間。在xml的beans裏面加入如下代碼即可

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

http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd


Q2.元素 "context:component-scan" 的前綴 "context"未綁定

辦法:同樣的原因,引入即可

xmlns:context="http://www.springframework.org/schema/context"
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd

(注意:spring的命名空間如果不加入版本號,比如spring-mvc-3.0.xsd去掉3.0版本號,就默認是最新的版本,在myeclipse裏面可以按住CTRL鍵跟進去,查看具體的版本信息)


Q3.java.lang.ClassNotFoundException: org.springframework.dao.support.DaoSupport

辦法:缺少spring-tx.jar,引入即可


Q4.PropertyAccessException 1: org.springframework.beans.MethodInvocationException: Property 'dataSource

辦法:配置dao之後出現的問題,原因是缺少spring-jdbc包,引入即可

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章