用的CGLIB代理的,不知道哪个出错了,不用CGLIB代理的话,就又会出现代理对象找不到该方法的异常
求解决

解决方案 »

  1.   

    下面是BaseAction.javapackage cn.han.action;import java.lang.reflect.ParameterizedType;
    import java.lang.reflect.Type;import com.opensymphony.xwork2.Action;
    import com.opensymphony.xwork2.ActionSupport;
    import com.opensymphony.xwork2.ModelDriven;
    @SuppressWarnings("serial")
    public class BaseAction<T> extends ActionSupport implements ModelDriven<T> { public T model; public BaseAction(){
    /*Type te=this.getClass().getGenericSuperclass();
    ParameterizedType type= (ParameterizedType)te;
    Class clazz=(Class) type.getActualTypeArguments()[0];*/

    Class clazz= GenericSuperClass.getGenericSuperclass(getClass());
    try {
    model=(T)clazz.newInstance();
    } catch (Exception e) {
    e.printStackTrace();
    }
    }

    @Override
    public String execute() throws Exception {
    // TODO Auto-generated method stub
    return null;
    } @Override
    public T getModel() {
    // TODO Auto-generated method stub
    return model;
    }

    }
      

  2.   

    下面是GenericSuperClass.javaimport java.lang.reflect.ParameterizedType;
    import java.lang.reflect.Type;public class GenericSuperClass { /**范类转换*/
    public static Class getGenericSuperclass(Class entity) {
    ParameterizedType type = (ParameterizedType) entity.getGenericSuperclass();
    Class entityClass = (Class) type.getActualTypeArguments()[0];
    return entityClass;
    }}
      

  3.   

    下面是实现类的Action   ElecTextAction.javaimport javax.annotation.Resource;import org.springframework.context.annotation.Scope;
    import org.springframework.stereotype.Controller;import cn.han.domain.ElecText;
    import cn.han.service.IElecTextService;
    @SuppressWarnings("serial")
    @Controller("elecTextAction")
    @Scope(value="prototype")
    public class ElecTextAction extends BaseAction<ElecText> {
        
    public ElecText et=super.model;
    @Resource(name=IElecTextService.SERVICE_NAME)
    public IElecTextService service;
    public String save(){
    service.save(et);
    return "asave";
    }

    }
      

  4.   

    http://www.blogjava.net/leisure/archive/2011/12/26/367185.html
    这个能解决你的问题。
      

  5.   

    LZ啊 你看看你的ElecTextAction  BaseAction这些对象的实例是不是给Spring管理,让它创建了代理。
    比如你用的ElecTextAction  对象的实例其实是代理。这时候你getClass() 这个Class对象可就不是你想要的Class了,这种情况下就会出现你说的异常。
      

  6.   

    ElecTextAction确实是Spring代理了。。那怎么弄呢
      

  7.   

    对没用过CGLIB。
    要解决的问题就是拿到真实对象的实例。比如A的实例a,创建代理后的实例proxiedA,你拿到proxiedA后怎么才能拿到a。起码到现在,JDK的代理机制了我是没找到拿甚是对象的办法。
    CGLIB也许方便些。