2013年10月31日星期四

May I ask a question , struts2 json and aop cglib when the asynchronous problem, thank you

 This post last edited by the ziyeibin on 2013-06-01 09:14:34
json serialization when the asynchronous get method , when in asynchronous error , can be used in the class @ JSON (serialize = false) solved, but also do not know why json serialization aop in the way, but do not know not really the problem,
exception as follows

2013-06-01 08:50:55,994 - org.apache.struts2.json.JSONWriter -140941 [http-8080-1] DEBUG  - com.bin.action.LoginAction.isExposeProxy()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.isExposeProxy()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
2013-06-01 08:50:55,995 - org.apache.struts2.json.JSONWriter -140942 [http-8080-1] DEBUG  - com.bin.action.LoginAction.isFrozen()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.isFrozen()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,002 - org.apache.struts2.json.JSONWriter -140949 [http-8080-1] DEBUG  - 
java.lang.NullPointerException
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,004 - org.apache.struts2.json.JSONWriter -140951 [http-8080-1] DEBUG  - com.bin.action.LoginAction.isPreFiltered()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.isPreFiltered()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,004 - org.apache.struts2.json.JSONWriter -140951 [http-8080-1] DEBUG  - com.bin.action.LoginAction.getProxiedInterfaces()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.getProxiedInterfaces()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,005 - org.apache.struts2.json.JSONWriter -140952 [http-8080-1] DEBUG  - com.bin.action.LoginAction.isProxyTargetClass()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.isProxyTargetClass()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,006 - org.apache.struts2.json.JSONWriter -140953 [http-8080-1] DEBUG  - 
java.lang.NullPointerException
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,007 - org.apache.struts2.json.JSONWriter -140954 [http-8080-1] DEBUG  - com.bin.action.LoginAction.getTargetClass()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.getTargetClass()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)
2013-06-01 08:50:56,008 - org.apache.struts2.json.JSONWriter -140955 [http-8080-1] DEBUG  - com.bin.action.LoginAction.getTargetSource()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.getTargetSource()
at java.lang.Class.getMethod(Unknown Source)
at org.apache.struts2.json.JSONWriter.findBaseAccessor(JSONWriter.java:294)
at org.apache.struts2.json.JSONWriter.bean(JSONWriter.java:202)
at org.apache.struts2.json.JSONWriter.processCustom(JSONWriter.java:178)
at org.apache.struts2.json.JSONWriter.process(JSONWriter.java:168)
at org.apache.struts2.json.JSONWriter.value(JSONWriter.java:134)
at org.apache.struts2.json.JSONWriter.write(JSONWriter.java:102)
at org.apache.struts2.json.JSONUtil.serialize(JSONUtil.java:116)
at org.apache.struts2.json.JSONResult.createJSONString(JSONResult.java:197)
at org.apache.struts2.json.JSONResult.execute(JSONResult.java:171)


Action class :

package com.bin.action;
@Scope("prototype")
@Controller
public class LoginAction extends ActionSupport implements ServletRequestAware{
private static Logger log = Logger.getLogger(LoginAction.class);
@Resource
private LoginService loginService;
private HttpServletRequest request;

private User user;
private String msg;

public String execute() throws Exception {
if (user == null || user.getAccount().equals("")
|| user.getPassword().equals("")) {
return LOGIN;
}
User userInfo = loginService.getUserInfo(user.getAccount());
if (userInfo == null) {
setMsg("找不到该用户,请检查账户是否正确");
} else if (user.getPassword().equals(userInfo.getPassword())) {
setMsg("success");
ServletActionContext.getContext().getSession().put("user", userInfo);
} else if (!user.getPassword().equals(userInfo.getPassword())) {
setMsg("密码错误,请检查密码是否正确");
}
return SUCCESS;
}
@Override
public void setServletRequest(HttpServletRequest request) {
this.request = request;
}

public void setLoginService(LoginService loginService) {
this.loginService = loginService;
}
@JSON(serialize=false)
public User getUser() {
return user;
}

public void setUser(User user) {
this.user = user;
}
    
public String getMsg() {
return msg;
}

public void setMsg(String msg) {
this.msg = msg;
}
}


struts.xml
		<action name="login" class="loginAction">
<result type="json">
</result>
</action>

aop categories:

@Repository
@Aspect
public class ExceptionAspect {
   @Pointcut("execution(* com.bin.action.*.*(..) throws Exception)")  
    private void anyMethod() {}
  @AfterThrowing(pointcut="anyMethod()",throwing="e")  
    public void doAfterThrowing(JoinPoint jp,Exception e) {
        System.out.println("异常通知:"+jp.getSignature().getName());
        e.printStackTrace();
    }  



 <aop:aspectj-autoproxy  proxy-target-class="true"/>

Note that I cut with aop service layer is no problem , but I hope to be able to cut into the action this AOP layer , do not know the expression has no problem, thank you
------ Solution ---- ----------------------------------------
unfamiliar with the landlord said those things .
But the vast majority of cases java.lang.NoSuchMethodException this exception is the wrong version of a package . For example a.jar cited B.class (version1), but the landlord 's operating environment is more than a B.class or is there a wrong version of B.class.
------ For reference only - -------------------------------------


Thank you upstairs to answer
but not reported method is to write my own java:
eg : java.lang.NoSuchMethodException: com.bin.action.LoginAction.getTargetSource ()
java.lang.NoSuchMethodException: com.bin.action.LoginAction.getTargetClass ()

I did not write these methods go , this is a bit like aop in the way, but I could not find in the Aspect which seems appropriate method ,
I also tried some of the latest update package into the jar , but it does not work
------ For reference only ----------------- ----------------------
does not solve now , what is the reason , I also encountered the same problem , if the landlord is resolved, hoping to informed solutions should be grateful

没有评论:

发表评论