最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ByteBuddy 的 ElementMatchers#nameStartsWith 使用什么算法?

ByteBuddy 的 ElementMatchers#nameStartsWith 使用什么算法?

倚天杖 2022-12-28 16:47:07
假設(shè)我想將 應(yīng)用于@Advice.OnMethodEnter中聲明的方法org.springframework.web.context.support.GenericWebApplicationContext。為此,我編寫了這個最小代理:public class SequenceAgent {  public static void premain(final String args,                             final Instrumentation instrumentation) {    new AgentBuilder.Default()        .with(new AgentBuilder.InitializationStrategy.SelfInjection.Eager())        .type(nameStartsWith(            "org.springframework.web.context.support.GenericWebApplicationContext"))        .transform((builder, typeDescription, classLoader, module) -> builder            .method(any()).intercept(Advice.to(SequenceAdvice.class)))        .installOn(instrumentation);  }  public static class SequenceAdvice {    @Advice.OnMethodEnter    static void enter(@Advice.This Object thiz, @Advice.Origin Method method,                      @Advice.AllArguments Object... args) {      String className = thiz.getClass().getName();      String methodName = method.getName();      System.out.println("Entered: " + className + "#" + methodName);    }  }}我希望此配置被過濾掉org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext,因為它不匹配org.springframework.web.context.support.GenericWebApplicationContext,但看起來對此類對象的方法調(diào)用也被攔截:import org.springframework.boot.web.servlet.context.AnnotationConfigServletWebServerApplicationContext;public class AgentTest {    public static void main(String[] args) {        AnnotationConfigServletWebServerApplicationContext context =                new AnnotationConfigServletWebServerApplicationContext();        context.containsBean("SomeBean");    }}當附加到代理并運行時,它會打印出來(為了便于閱讀而包裝):Entered: org.springframework.boot.web.servlet.context.    AnnotationConfigServletWebServerApplicationContext    #getResourcePatternResolver...Entered: org.springframework.boot.web.servlet.context.    AnnotationConfigServletWebServerApplicationContext    #getResourceCache
查看完整描述

1 回答

?
一只甜甜圈

TA貢獻1836條經(jīng)驗 獲得超5個贊

字節(jié)好友使用 String.startsWith。

您所看到的是由于 Byte Buddy 檢測類,而不是實例。在某種程度上,想想 Byte Buddy 將通知代碼復制到目標方法中。

結(jié)果,所有子類都會受到影響。為了做你正在做的事情,你需要在調(diào)用期間檢查實例類的類型,就像你想在 Java 中實現(xiàn)它一樣。


查看完整回答
反對 回復 2022-12-28
  • 1 回答
  • 0 關(guān)注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號