配置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包,引入即可

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