簡體   English   中英

ByteBuddy和注釋

[英]ByteBuddy and annotations

我有一堆在普通JDK上運行的WebServices,我需要攔截所有公共方法才能做某事。 有些方法正在使用@WebParam注釋。 使用ByteBuddy對WebService進行子類化會從覆蓋方法中刪除@WebParam注釋,並且該服務不再按預期工作。

這是一個示例簽名

public Something fetch( @WebParam( name="Query" ) QueryCriteria query )

這就是我如何使用ByteBuddy

new ByteBuddy( )
    .subclass( implementationClass )
    .method( isPublic( ).and( isDeclaredBy( implementationClass ) ) )
    .intercept( 
            MethodDelegation.to( new WebServiceInterceptor( ) )
            .andThen( SuperMethodCall.INSTANCE ) )
    .annotateType( implementationClass.getAnnotations( ) )
    .make( )

我知道有一種方法來注釋參數,但它需要有關方法參數的特殊知識(因為只有一些參數被注釋)。 我想要做的只是要求ByteBuddy注釋我的類與超類相同,包括所有重寫方法的所有參數。

subclass( implementationClass )
.annotateType( LIKE_SUPERCLASS )
.method( )
.intercept( ... )
.annotateMethod( LIKE_SUPER_INCLUDING_PARAMS )

有任何想法嗎?

BR,Paci

管理自己找到解決方案。

new ByteBuddy( )
    .withAttribute( new TypeAttributeAppender.ForInstrumentedType( AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )
    .withDefaultMethodAttributeAppender( new MethodAttributeAppender.ForInstrumentedMethod(AnnotationAppender.ValueFilter.AppendDefaults.INSTANCE ) )

會做的。

Br,Paci

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM