[英]How to use bytebuddy to set annotation @Value in private variable
enter image description here在此处输入图像描述
Class<?> metricTags = new ByteBuddy().subclass(Object.class).name("demo.metrics.MetricTags").annotateType(AnnotationDescription.Builder.ofType(Component.class).build()).annotateType(AnnotationDescription.Builder.ofType(Data.class).build()).defineField("sourceApp", String.class, Visibility.PUBLIC).annotateField(AnnotationDescription.Builder.ofType(Value.class).define("sourceApp", "dsdw23").build()).defineField("sourceServiceNamespace", String.class, Visibility.PRIVATE).defineField("sourceServiceName", String.class, Visibility.PRIVATE).defineField("protocol", String.class, Visibility.PRIVATE).value("http").defineField("appName", String.class, Visibility.PRIVATE).make().load(AgentMain.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER).getLoaded();
report error: Caused by: java.lang.IllegalArgumentException: interface lombok.Value does not define a property named sourceApp报错: 原因:java.lang.IllegalArgumentException: interface lombok.Value没有定义一个名为sourceApp的属性
The error indicates that the Value annotation does not define a property of thst name.该错误表明 Value 注释未定义第一个名称的属性。 You can only define properties that are declared by the annotation type.
您只能定义由注释类型声明的属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.