当前位置: 代码迷 >> JavaScript >> Struts2.1.8跟struts2-json-plugin集成时无法返回JSON的原因及解决方案
  详细解决方案

Struts2.1.8跟struts2-json-plugin集成时无法返回JSON的原因及解决方案

热度:353   发布时间:2012-08-27 21:21:57.0
Struts2.1.8和struts2-json-plugin集成时无法返回JSON的原因及解决方案

最近的SSH项目中集成了struts2-json-plugin用以实现JQUERY的AJAX调用,但调用时会出现下列异常信息,现提供异常原因及解决方案。

?? ?异常:

org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.apache.commons.dbcp.PoolingDataSource$PoolGuardConnectionWrapper with modifiers "public"

?

?? ?出现原因:

?? ?1、在返回JSON字符串的类中,其成员变量如果是由Spring注入的并提供了getter方法,则抛此异常。

?? ?2、懒加载导致。

?? ?

?? ?解决方案:

?? ?1、Spring注入的方法只提供setter方法,不提供getter方法。

?? ?2、排除hibernateLazyInitializer属性。在配置中把hibernateLazyInitializer属性除外:

?? ?<result name="returnValue" type="json">
?? ? ? ?<param name="excludeProperties">.*hibernateLazyInitializer</param>
?? ?</result>

  相关解决方案