diff --git a/src/main/java/com/ryantenney/metrics/spring/AbstractMetricMethodInterceptor.java b/src/main/java/com/ryantenney/metrics/spring/AbstractMetricMethodInterceptor.java
index 3ea83162..48db7d23 100644
--- a/src/main/java/com/ryantenney/metrics/spring/AbstractMetricMethodInterceptor.java
+++ b/src/main/java/com/ryantenney/metrics/spring/AbstractMetricMethodInterceptor.java
@@ -52,9 +52,23 @@ abstract class AbstractMetricMethodInterceptor implemen
ReflectionUtils.doWithMethods(targetClass, this, methodFilter);
}
+ private AnnotationMetricPair getAnnotationMetricPair(MethodInvocation invocation) {
+ final Method method = invocation.getMethod();
+ AnnotationMetricPair annotationMetricPair = metrics.get(MethodKey.forMethod(method));
+ if (annotationMetricPair != null) {
+ return annotationMetricPair;
+ }
+ for (MethodKey methodKey: metrics.keySet()) {
+ if (methodKey.isCompatibleWith(invocation)) {
+ return metrics.get(methodKey);
+ }
+ }
+ return null;
+ }
+
@Override
public Object invoke(MethodInvocation invocation) throws Throwable {
- final AnnotationMetricPair annotationMetricPair = metrics.get(MethodKey.forMethod(invocation.getMethod()));
+ final AnnotationMetricPair annotationMetricPair = getAnnotationMetricPair(invocation);
if (annotationMetricPair != null) {
return invoke(invocation, annotationMetricPair.getMeter(), annotationMetricPair.getAnnotation());
}
diff --git a/src/main/java/com/ryantenney/metrics/spring/MethodKey.java b/src/main/java/com/ryantenney/metrics/spring/MethodKey.java
index b4f94378..0c25a126 100644
--- a/src/main/java/com/ryantenney/metrics/spring/MethodKey.java
+++ b/src/main/java/com/ryantenney/metrics/spring/MethodKey.java
@@ -18,6 +18,8 @@
import java.lang.reflect.Method;
import java.util.Arrays;
+import org.aopalliance.intercept.MethodInvocation;
+
class MethodKey {
private final String name;
@@ -36,6 +38,32 @@ private MethodKey(Method method) {
this.hashCode = computeHashCode();
}
+ public boolean isCompatibleWith(MethodInvocation invocation) {
+ final Method invokedMethod = invocation.getMethod();
+ final Object[] invokedParameters = invocation.getArguments();
+
+ if (!name.equals(invokedMethod.getName())) {
+ return false;
+ }
+ if (!invokedMethod.getReturnType().isAssignableFrom(returnType)) {
+ return false;
+ }
+ if (invokedParameters.length != parameterTypes.length) {
+ return false;
+ }
+ for (int i=0; i invokedParameterClass = invokedParameters[i].getClass();
+ Class> parameterClass = parameterTypes[i];
+ if (!parameterClass.isAssignableFrom(invokedParameterClass)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
@Override
public int hashCode() {
return hashCode;
diff --git a/src/test/java/com/ryantenney/metrics/spring/MeteredClassImpementsInterfaceTest.java b/src/test/java/com/ryantenney/metrics/spring/MeteredClassImpementsInterfaceTest.java
index 6a5d227d..5402f683 100644
--- a/src/test/java/com/ryantenney/metrics/spring/MeteredClassImpementsInterfaceTest.java
+++ b/src/test/java/com/ryantenney/metrics/spring/MeteredClassImpementsInterfaceTest.java
@@ -38,22 +38,23 @@
/**
* Purpose of test:
- * Verify that calling a method from a class implementing an interface
+ * Verify that calling a method from a class implementing an interface
* but annotated at the class level doesn't throw an NPE
* Also verifies that it does register metrics.
*/
public class MeteredClassImpementsInterfaceTest {
- MeteredClassInterface meteredClass;
+ MeteredClassInterface