简体   繁体   中英

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

The error indicates that the Value annotation does not define a property of thst name. You can only define properties that are declared by the annotation type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM