我必须在运行时更改java中模型类的注释。这个场景是在我的网页上,当我改变dropdown的值并点击apply按钮时,我有一个下拉列表,我必须根据下拉列表的值在我的模型类上添加注释。
为此,我使用javaassit在类上添加了注释。我认为注释被正确地应用了,但是我无法重新加载这个类。我已经尝试过使用HotswapAgent来完成此任务。但它看起来不像是在工作。
我正在使用play框架
任何帮助都将受到高度的感谢。
ClassPool pool= Enhancer.newClassPool();
CtClass cc = pool.get("Test");
ClassFile cf = cc.getClassFile();
ConstPool cp = cf.getConstPool();
// Code for creating and adding annotation comes here.....
ByteArrayOutputStream bos = new ByteArrayOutputStream();
DataOutputStream os = new DataOutputStream(bos);
cf.write(os);
os.close();
ClassDefinition cd = new ClassDefinition(Test.class, bos.toByteArray());
HotswapAgent hh = new HotswapAgent();
hh.reload(cd);发布于 2020-03-03 09:05:36
请尝试此操作,如果使用相同的类加载器,则可以加载它
https://www.baeldung.com/java-reflection-change-annotation-params
https://stackoverflow.com/questions/16771043
复制相似问题