【问题标题】:ByteBuddy and annotationsByteBuddy 和注释
【发布时间】:2015-10-15 06:22:16
【问题描述】:

我有一堆在普通 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,帕西

【问题讨论】:

    标签: java byte-buddy


    【解决方案1】:

    设法自己找到解决方案。

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

    会成功的。

    Br,帕西

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-06-06
      • 1970-01-01
      相关资源
      最近更新 更多