注解
@Retention(RetentionPolicy.RUNTIME)
@Target({ ElementType.METHOD})
public @interface PublishMetric {
}
Run Code Online (Sandbox Code Playgroud)
拦截器
public class PublishMetricInterceptor implements MethodInterceptor {
@Override
public Object invoke(MethodInvocation methodInvocation) throws Throwable {
System.out.println("invoked");
return methodInvocation.proceed();
}
}
Run Code Online (Sandbox Code Playgroud)
指南模块
public class MetricsModule extends AbstractModule {
@Override
protected void configure() {
bindInterceptor(any(), annotatedWith(PublishMetric.class), new PublishMetricInterceptor());
}
@Provides
@Singleton
public Dummy getDummy(Client client) {
return new Dummy(client);
}
}
Run Code Online (Sandbox Code Playgroud)
用法
public class Dummy {
private final Client client;
@Inject
public Dummy(final Client client) {
this.client = client;
}
@PublishMetric
public String …Run Code Online (Sandbox Code Playgroud)