Struts2Action使用插件返回json时报错问题
来源:互联网 发布:战地4优化怎么样 编辑:程序博客网 时间:2024/06/05 15:46
@JSON(serialize=false) public AuthorityService getAuthorityService() { return authorityService; }
Struts2Action使用插件返回json时报如下错误:
<span style="font-size:18px;">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"</span>
主要原因:struts会将action中定义的一些变量序列化转换成json格式,需要调用对象的一系列get方法(例子中调用authorityService和authorities的get方法),并调用以上两个变量的成员变量的get方法将其内容组成json格式。但是在序列化authorityService时,由于其成员变量中含有含有接口所以会报错。
解决方案:
1)修改配置文件:指定序列化的根节点,这样data就是从authorities的根节点以下的数据,不需要用data.authorities
<package name="super_admin" extends="json-default" namespace="/superadmin"> <action name="allAuthorities" class="edu.bjfu.action.AuthoritiesAction"> <result type="json"><param name="root">authorities</param></result> </action> </package>
2) 修改java代码:让编译器不对authorityService序列化
@JSON(serialize=false) public AuthorityService getAuthorityService() { return authorityService; }
3)此外貌似可以通过配置文件的excude和include来指定需要序列化的对象,我没有自己去试!
4)可以去掉不必要的get方法也可以解决
转载自:http://www.cnblogs.com/xiaoyaorensheng/archive/2013/01/02/2842302.html
0 0
- Struts2Action使用插件返回json时报错问题
- 使用Hibernate返回自定义类型时报错的问题
- 使用Hibernate返回自定义类型时报错的问题
- 使用maven的tomcat插件启动时报错问题
- 使用maven插件时报错
- struts2返回json数据 ——不使用json插件
- Struts2Action+JQuery+jsp获取json数据
- struts2action与struts.xml传参问题
- Eclipse 4.4(luna) 安装fatjar插件时报错的问题
- Eclipse 4.4(luna) 安装fatjar插件时报错的问题
- Eclipse 4.4(luna) 安装fatjar插件时报错的问题
- Eclipse 安装fatjar插件时报错的问题
- Eclipse 4.4(luna) 安装fatjar插件时报错的问题
- 浏览器JSON的插件(JSON-handle)使用问题
- ajaxform插件使用时报错ajaxSubmit() is not a function
- Struts2 json插件返回json数据配置
- 关于使用struts2-json-plugin 插件,Json返回List对象数据为空解决方案
- 使用struts2返回json
- python之函数总结1
- 写个脚本分类文件
- selenium自动化常见问题及优化
- 从头学android_网络图片查看器
- ThinkPHP Model类自动验证功能解析
- Struts2Action使用插件返回json时报错问题
- 解决Unable to open liblaunch_sim.dylib. Try reinstalling Xcode or the simulator runtime
- 51NOD 1116 K进制下的大数(字符串取模 + 枚举)
- 反思“研究生之死” 别止于声讨导师
- 从源代码分析Android-Universal-Image-Loader的缓存处理机制
- 正确使用iOS常量(const)、enum以及宏(#define)(收藏)
- 【深度学习】caffe 中的一些参数介绍
- Delphi 中的哈希表(1): THashedStringList
- Xcode 7.3 自定义类无法自动联想的解决办法