title: How to use byte-buddy in springboot
body: <p>I want to use byte-buddy to intercept methods with java annotation. A simplified example is as follows：</p>
  <ul>
  <li>Annotation</li>
  </ul>
  <pre><code>@Target(ElementType.METHOD)
  @Retention(RetentionPolicy.RUNTIME)
  @Documented
  public @interface TraceLog {
      String logName() default &quot;&quot;;
  }
  </code></pre>
  <ul>
  <li>The Interceptor class is</li>
  </ul>
  <pre><code>public class TraceLogInterceptor {
      @RuntimeType
      public static Object handleTraceLog(@Origin Method method,
                                          @AllArguments Object[] args,
                                          @SuperCall Callable&lt;?&gt; superCall) throws Exception {
           TraceLog traceLogAnnotation = method.getAnnotation(TraceLog.class);
           System.out.println(traceLogAnnotation.logName());
           superCall.call();
      }
  }
  </code></pre>
  <ul>
  <li>The service class is</li>
  </ul>
  <pre><code>public class HelloServiceImpl {
      @TraceLog(logName = &quot;myLog&quot;)
      public String writeHello(String name) {
          return &quot;Hello &quot; + name;
      }
  }
  </code></pre>
  <ul>
  <li>The test method is</li>
  </ul>
  <pre><code> @Test
      public void writeHello() throws IllegalAccessException, InstantiationException, IOException, NoSuchMethodException, InvocationTargetException {
          DynamicType.Unloaded&lt;?&gt; dynamicType =
                  new ByteBuddy()
                          .subclass(HelloServiceImpl.class)
                          .method(ElementMatchers.isAnnotatedWith(TraceLog.class))
                          .intercept(MethodDelegation.to(TraceLogInterceptor.class))
                          .make();
  
          HelloServiceImpl helloService = (HelloServiceImpl) dynamicType.load(this.getClass().getClassLoader())
                  .getLoaded()
                  .getConstructor()
                  .newInstance();
          System.out.println(helloService.writeHello(&quot;XXXXX&quot;));
      }
  </code></pre>
  <p>It can work. However, I want to know how to inject the interceptor(TraceLogInterceptor) to spring. And I also want to know how to intercept all methods with the <code>@TraceLog</code> annotation and generate the corresponding proxy class without specifying the superclass(<code>new ByteBuddy().subclass(xxx)</code>). Thanks!</p>