`
noble510520
  • 浏览: 54427 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

spring 整合 struts

 
阅读更多

struts配置

objectFactory

在struts.xml添加,用spring工厂管理action对象

<constant name="struts.objectFactory" value="spring" />

action的class

以前配置action的时候是

<action name="xxxx" class="包名.类名" ></action>

现在改为

<action name="xxxx" class="id" ></action>

id是在spring中配置的action bean的id

通过id访问,才能实现由spring管理action对象

spring配置

当出现ConversionNotSupportedException异常时
Caused by: org.springframework.beans.ConversionNotSupportedException:
Failed to convert property value of type [java.util.LinkedHashMap] to required type [java.util.Map] for property 'fieldErrors'

原因

如果访问这个action的时候,出现这个错误,那是因为,action bean 配置了autowire="byType"

因为,action是继承ActionSupport,ActionSupport里面有一个属性是fieldErrors,并且有seter方法

所以spring会自动装配fieldErrors,spring用java.util.LinkedHashMap去装配java.util.Map,这在jdk里面是向下转型,但是spring显然更安全,会直接抛出ConversionNotSupportedException

解决方案

将spring的自动装配改为autowire="byName"



查看原文:http://139.129.55.235/2016/05/31/spring-%e6%95%b4%e5%90%88-struts/
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics