用的CGLIB代理的,不知道哪个出错了,不用CGLIB代理的话,就又会出现代理对象找不到该方法的异常
求解决
求解决
解决方案 »
- 大侠们,在配置hibernate是出现类型不匹配,该怎么办?
- UML关联关系 --- java编码设计实现
- 急,求助。
- 一个web服务器的非常基本的问题,学过J2EE的都会
- 关于缓存机制的想法,请教各位,听说CSDN上大牛多
- struts的奇怪問題!
- 3.0many-to-one子查父lazy的问题
- 精通EJB第三版(英文版)下载
- 紧急:applet中如何实现页面跳转???
- j2ee应用生命周期??
- tomcat6.0 后台报错 数据库是SQL2000 如何查是哪个表 或者 哪个操作引起的 不知道怎么查问题啊
- java.lang.reflect.InvocationTargetException求帮助啊
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;
}
}
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;
}}
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";
}
}
这个能解决你的问题。
比如你用的ElecTextAction 对象的实例其实是代理。这时候你getClass() 这个Class对象可就不是你想要的Class了,这种情况下就会出现你说的异常。
要解决的问题就是拿到真实对象的实例。比如A的实例a,创建代理后的实例proxiedA,你拿到proxiedA后怎么才能拿到a。起码到现在,JDK的代理机制了我是没找到拿甚是对象的办法。
CGLIB也许方便些。