我想使用Byte-Buddy来生成注释,我能够为简单的注释实现这一点。生成嵌套注释的正确Byte-Buddy语法是什么?
例如,我想生成以下包含嵌套注释的注释@MessageDriven:
@MessageDriven(
activationConfig={
@ActivationConfigProperty(propertyName="destination", propertyValue="remoteBidsWantedJMS/TOPIC.BIDSWANTED.QUOTEWANTEDSEVENT"),
@ActivationConfigProperty(propertyName="providerAdapterJNDI", propertyValue="java:/RemoteBidsWantedJMSProvider"),
@ActivationConfigProperty(propertyName="reconnectAttempts", propertyValue="60"),
@ActivationConfigProperty(propertyName="reconnectInterval", propertyValue="10"),
@ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="Auto-acknowledge"),
@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
@ActivationConfigProperty(propertyName="subscriptionDurability", propertyValue="NonDurable"),
@ActivationConfigProperty(propertyName="maxSession", propertyValue="1")
})我当前的语法有什么问题?
DynamicType.Unloaded dynamicTypeBuilder2 = new ByteBuddy()
.redefine(QuoteWantedsEventProcessorBean.class)
.name("com.tmcbonds.messaging.QuoteWantedsEventProcessorBean_BYTEBUDDY_REDEFINE_" + i)
.annotateType(AnnotationDescription.Builder.ofType(Pool.class)
.define("value", "TESTVALUE")
.build())
.annotateType(AnnotationDescription.Builder.ofType(MessageDriven.class)
.defineTypeArray("activationConfig", ActivationConfigProperty.class)
.define("propertyName", "destination")
.define("propertyValue", "remoteBidsWantedJMS/TOPIC.BIDSWANTED.QUOTEWANTEDSEVENT")
.build())
.make();例外情况是:
线程"main“java.lang.IllegalArgumentException中出现异常:无法将接口javax.ejb.ActivationConfigProperty分配给位于net.bytebuddy.description.annotation.AnnotationDescription$Builder.defineTypeArray(AnnotationDescription.java:1029)的net.bytebuddy.description.annotation.AnnotationDescription$Builder.define(AnnotationDescription.java:852)处的activationConfig
谢谢!
发布于 2017-11-04 00:27:25
我能够找出正确的语法来创建带有嵌套注释的类文件:
Unloaded<QuoteWantedsEventProcessorBean> dynamicTypeBuilder = new ByteBuddy()
.redefine(QuoteWantedsEventProcessorBean.class)
.name("com.tmcbonds.messaging.QuoteWantedsEventProcessorBean_BYTEBUDDY_REDEFINE_" + i)
.annotateType(AnnotationDescription.Builder.ofType(MessageDriven.class)
.defineAnnotationArray(
"activationConfig",
new TypeDescription.ForLoadedType(ActivationConfigProperty.class),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "messageSelector")
.define("propertyValue", "" + i)
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "destination")
.define("propertyValue", "remoteBidsWantedJMS/TOPIC.BIDSWANTED.QUOTEWANTEDSEVENT")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "providerAdapterJNDI")
.define("propertyValue", "java:/RemoteBidsWantedJMSProvider")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "reconnectAttempts")
.define("propertyValue", "60")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "reconnectInterval")
.define("propertyValue", "10")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "acknowledgeMode")
.define("propertyValue", "Auto-acknowledge")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "destinationType")
.define("propertyValue", "javax.jms.Topic")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "subscriptionDurability")
.define("propertyValue", "NonDurable")
.build(),
AnnotationDescription.Builder.ofType(ActivationConfigProperty.class)
.define("propertyName", "maxSession")
.define("propertyValue", "1")
.build()
)
.build())
.make();它在类文件中生成以下内容:
@MessageDriven(description = "", activationConfig = {
@ActivationConfigProperty(propertyName = "messageSelector", propertyValue = "0"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "remoteBidsWantedJMS/TOPIC.BIDSWANTED.QUOTEWANTEDSEVENT"),
@ActivationConfigProperty(propertyName = "providerAdapterJNDI", propertyValue = "java:/RemoteBidsWantedJMSProvider"),
@ActivationConfigProperty(propertyName = "reconnectAttempts", propertyValue = "60"),
@ActivationConfigProperty(propertyName = "reconnectInterval", propertyValue = "10"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"),
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Topic"),
@ActivationConfigProperty(propertyName = "subscriptionDurability", propertyValue = "NonDurable"),
@ActivationConfigProperty(propertyName = "maxSession", propertyValue = "1") }, mappedName = "", messageListenerInterface = Object.class, name = "")https://stackoverflow.com/questions/47098810
复制相似问题