Spring MVC常见bug总结----持续更新中

本文总结了Spring MVC配置过程中遇到的问题,包括Springmvc-servlet.xml的schema引用错误和配置bug。通过检查命名空间定义,解决了找不到文件的问题。在尝试依赖注入时,遇到表单数据绑定异常,由于提交数据为String类型,而模型类属性可能为其他类型,解决方案是创建一个与User类属性对应的UserForm类进行中间转换。
摘要由CSDN通过智能技术生成

一、

  Spring MVC的配置文件Springmvc-servlet.xml报错,在添加

<context:component-scan base-package="controller" />
  来指定控制器所在的包时,窗口显示红叉,报错内容为:

Multiple annotations found at this line:
    - schema_reference.4: Failed to read schema document 'http://www.springframework.org/schema/
     springcontext.xsd', because 1) could not find the document; 2) the document could not be read; 3) the root
     element of the document is not <xsd:schema>.
    - cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element
     'context:component-scan'.

  经过检查,发现时springmvc-servlet的头中,关于命名空间(是不是这么说的。。。)的定义有误,导致找不到我对应的文件。

  之前,我的头定义如下:

 

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

xsd等没有指定正确的文件版本,根据自己的jar包版本做修改如下:

<beans xmlns:beans="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.o
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值