ClassPool pool = ClassPool.getDefault();
pool.insertClassPath(new ClassClassPath(JpaRepository.class));
CtClass superClass = pool.get(JpaRepository.class.getName());
superClass.setGenericSignature("<T:Ljava/lang/Object;ID::Ljava/io/Serializable;>Ljava/lang/Object;Lorg/springframework/data/repository/PagingAndSortingRepository<Lcom/his/jtec/domain/Gender;Ljava/lang/Long;>;");
CtClass cc = pool.makeInterface("com.his.jtec.domain.GenderRepo");
cc.defrost();
cc.setSuperclass(superClass);
ConstPool constpool = cc.getClassFile().getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation("Inject", constpool);
attr.addAnnotation(annot);
cc.getClassFile().addAttribute(attr);
repositoryClass = cc.toClass();
Method method = repositoryClass.getMethod("findAll", (Class<?>[])null);
responseMsg = method.invoke(repositoryClass.getClass());
java.lang.IllegalArgumentException: object is not an instance of declaring class at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497)
Aucun commentaire:
Enregistrer un commentaire