简体   繁体   English

ByteBuddy - 重新定义给定包中的所有类

[英]ByteBuddy - redefine all classes that are in a given pacakge

I have a package called com.company.beans .我有一个名为 com.company.beans 的com.company.beans What I would like to do, is to upperCase and trim all fields of type String for each class from this package.我想要做的是upperCase并从这个 package 中为每个 class trim所有String类型的字段。 I've seen this post Using Bytebuddy to intercept setter which seems to be a good solution to what I want to do.我看过这篇文章Using Bytebuddy to intercept setter这似乎是我想做的一个很好的解决方案。

Here is the piece of code I'm trying to redefine:这是我试图重新定义的一段代码:

 bb.subclass(BaseUser.class) // how to specify my package ? 
            .method(isDeclaredBy(BaseUser.class).and(isSetter()))
            .intercept(MethodDelegation.to(interceptor))
            .make()
            .load(BaseUser.class.getClassLoader(), ClassLoadingStrategy.Default.WRAPPER);

How do I specify all classes from a given package?如何指定给定 package 中的所有类? Also, I'm using spring boot.另外,我正在使用 spring 引导。 Where should I put my ByteBuddy configuration?我应该把我的 ByteBuddy 配置放在哪里?

Thanks.谢谢。

There are libraries to scan the class path such as Class Graph which you can use for this purpose.有一些库可以扫描 class 路径,例如Class Graph ,您可以将其用于此目的。 There's nothing in Byte Buddy for it since this is considered a different domain. Byte Buddy 中没有任何内容,因为这被认为是一个不同的域。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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