Reputation: 11
Using ByteBuddy, I need create a new class with an annotation. This annotation has a Class[] property. I set the value using a class creating with Byte buddy
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface MyAnnotation {
Class<?>[] configuration() default {};
}
My class with annotation:
final Class<?> configClass = new ByteBuddy()
.subclass(Object.class)
.annotateType(AnnotationDescription.Builder.ofType(MyAnnotation.class)
.defineTypeArray("configuration", myConfigClass)
.build())
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
But this doesn't work, there is no annotation on the class. It works when I use a not byte buddy created class.
Here is my byte buddy created class :
final Class<? extends BasicConfig> myConfigClass = new ByteBuddy()
.subclass(BasicRibbonConfig.class)
.method(ElementMatchers.named("getTargetApplication"))
.intercept(FixedValue.value(targetApplication))
.make()
.load(getClass().getClassLoader(), ClassLoadingStrategy.Default.WRAPPER)
.getLoaded();
Any ideas?
Upvotes: 1
Views: 375
Reputation: 11
It was a class loader issue. I changed the configuration:
.load(ribbonConfig.getClassLoader(), INJECTION)
Upvotes: 0