在struts2+spring4+spring security4整合过程中遇到如下的问题,表现的错误信息为以下几种:
1.


Cannot convert value of type [org.springframework.security.web.DefaultSecurityFilterChain] to required type [java language=".lang.String"][/java] for property 'fieldErrors[org.springframework.security.filterChains][0]': no matching editors or conversion strategy found
Failed to convert property value of type 'java.util.LinkedHashMap' to required type 'java.util.Map' for property 'fieldErrors'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.security.web.DefaultSecurityFilterChain] to required type [java language=".lang.String"][/java] for property 'fieldErrors[org.springframework.security.filterChains][0]': no matching editors or conversion strategy found
Unable to instantiate Action, com.adamfei.action.RecogDataGeneralSearchAction, defined for 'generalSearchRecogData' in namespace '/'Failed to convert property value of type 'java.util.LinkedHashMap' to required type 'java.util.Map' for property 'fieldErrors'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.security.web.DefaultSecurityFilterChain] to required type [java language=".lang.String"][/java] for property 'fieldErrors[org.springframework.security.filterChains][0]': no matching editors or conversion strategy found

2.

no result defined for action XXX and no result input

其中第一个问题,按照思路来解决就是在action中添加java.util.LinkedHashMap类型的fieldErrors变量,但是添加之后遇到第2个问题,按照提示来解决是配置result的input视图资源,配置完成之后。没有错误。

但是在请求action过程中,通过firefox调试工具可以看到返回结果中int类型的数据已经转换成功,可是List类型的数据为null,后台验证List类型的数据不为null,所以问题出在类型转换过程中。果然从报错信息中发现如下:

org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.LinkedHashMap' to required type 'java.util.Map' for property 'fieldErrors'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.springframework.security.web.DefaultSecurityFilterChain] to required type [java language=".lang.String"][/java] for property 'fieldErrors[org.springframework.security.filterChains][0]': no matching editors or conversion strategy found

java.lang.IllegalStateException: Cannot convert value of type [org.springframework.security.web.DefaultSecurityFilterChain] to required type [java language=".lang.String"][/java] for property 'fieldErrors[org.springframework.security.filterChains][0]': no matching editors or conversion strategy found

这说明这里在spring security框架中的filter chain中已经对数据进行转换,而没有采用struts2内置的转换插件。问题到这里看起来已经要解决了。解决思路一种是自己开发list转换插件,开发难度较大并且调试麻烦,另外struts2中内置的转换插件已经非常方便。所以这种解决思路不可采取。

最终在一个角落中发现解决方案尝试可解决:

解决方法如下:
将src/struts.xml中

<constant name="struts.objectFactory.spring.autoWire" value="type" />
修改为
<constant name="struts.objectFactory.spring.autoWire" value="name" />

这个是在struts2的配置文件中将bean的默认注入更改为name。问题至此已经初步解决。但是系统上线已经很长时间一直采用type方式自动注入。所以后期应该还有未知的问题在等着我解决。

总结一下:

1.SSH这些框架高度集成遇到诸如今天这样的问题的确很难解决,需要在遇到问题耐心尝试解决,细心分解。

2.在spring security4使用过程中发现对servlet的filter需要加深理解,看来基础不牢,学起来新东西也是费劲啊。

参考网址:http://www.csdn123.com/html/exception/578/578289_578287_578286.htm

struts2+spring4+spring security4集成遇到的诡异问题
Tagged on:         

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据