지정된 주석으로 주석 된 필드가있는 bean 클래스를 생성 할 수 있습니까? 빈은 생성 될 수 있지만 주석은 무엇인지 ... 나는 그것에 대해 아무 것도 찾을 수 없으므로 나는 그것에 대해 강한 의구심을 가지며 여기에 묻는 것이 유일한 방법입니다 ...CGLib - 일부 필드가있는 빈을 만들고 그 위에 주석을 추가 하시겠습니까?
// 도움이 될만한 것을 발견했습니다 ...이 코드를 확인하십시오. javassist 기능을 사용합니다.
// pool creation
ClassPool pool = ClassPool.getDefault();
// extracting the class
CtClass cc = pool.getCtClass(clazz.getName());
// looking for the method to apply the annotation on
CtField fieldDescriptor = cc.getDeclaredField(fieldName);
// create the annotation
ClassFile ccFile = cc.getClassFile();
ConstPool constpool = ccFile.getConstPool();
AnnotationsAttribute attr = new AnnotationsAttribute(constpool,
AnnotationsAttribute.visibleTag);
Annotation annot = new Annotation("sample.PersonneName", constpool);
annot.addMemberValue("name",
new StringMemberValue("World!! (dynamic annotation)", ccFile.getConstPool()));
attr.addAnnotation(annot);
// add the annotation to the method descriptor
fieldDescriptor.getFieldInfo().addAttribute(attr);
이 문제는 내가하는 방법이 할 수있는 방법이 ... 새로 만든 유형에 기존의 주석을 적용 모르겠입니다?
님이 주석 달았습니다. 요구 사항에 맞는 라이브러리를 작성했습니다. 내 업데이트 답변을 참조하십시오. –