【ssh学习笔记】struts处理json异常之JSONWriter can not access a member of class org.springframework.aop.TruePoin

时间:2022-12-20 14:24:59

Struts has detected an unhandled exception:

Messages:
  1. Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
  2. java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
  3. org.apache.struts2.json.JSONException: java.lang.IllegalAccessException: Class org.apache.struts2.json.JSONWriter can not access a member of class org.springframework.aop.TruePointcut with modifiers "public"
  4. 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.springframework.aop.TruePointcut with modifiers "public"
  5. 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.springframework.aop.TruePointcut with modifiers "public"


该类中UserManager不需要添加到json中,但是被添加了,造成了异常,解决方法,在getXXX()上面添加@JSON(serialize=false)
public class JsonAction extends ActionSupport {

/**
*
*/
private static final long serialVersionUID = -9040282050464969108L;

private String isSuccess = "success";

private List<Map<String, Object>> users = new ArrayList<Map<String, Object>>();

private UserManager userManager;



@JSON(name="result")
public String getIsSuccess() {
return isSuccess;
}


public void setIsSuccess(String isSuccess) {
this.isSuccess = isSuccess;
}


public List<Map<String, Object>> getUsers() {
return users;
}


public void setUsers(List<Map<String, Object>> users) {
this.users = users;
}

<span style="white-space:pre">@JSON(serialize=false)</span>public UserManager getUserManager() {return userManager;}public void setUserManager(UserManager userManager) {this.userManager = userManager;}@Overridepublic String execute() throws Exception {List<User> userList = userManager.listUsers();for(User user : userList){Map<String, Object> jsonMap = new HashMap<String, Object>();jsonMap.put("id", user.getId());jsonMap.put("username", user.getUsername());jsonMap.put("password", user.getPassword());users.add(jsonMap);}return SUCCESS;}}