Skip to content

fix spring_web aop no such method found exception#376

Merged
brian-brazil merged 5 commits intoprometheus:masterfrom
candyleer:fix_aop_no_class_defined
Apr 23, 2018
Merged

fix spring_web aop no such method found exception#376
brian-brazil merged 5 commits intoprometheus:masterfrom
candyleer:fix_aop_no_class_defined

Conversation

@candyleer
Copy link
Copy Markdown

@candyleer candyleer commented Apr 16, 2018

when i follow the instruction.i failed to make the metrics data ,cause:

java.lang.NoSuchMethodException: io.github.candyleer.prometheusdemo.PrometheusDemoApplication$$EnhancerBySpringCGLIB$$5772d178.springTest(java.lang.String)
        at java.base/java.lang.Class.getDeclaredMethod(Class.java:2432) ~[na:na]
        at io.prometheus.client.spring.web.MethodTimer.getAnnotation(MethodTimer.java:50) ~[classes!/:na]
        at io.prometheus.client.spring.web.MethodTimer.ensureSummary(MethodTimer.java:56) ~[classes!/:na]
        at io.prometheus.client.spring.web.MethodTimer.timeMethod(MethodTimer.java:107) ~[classes!/:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
        at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
        at java.base/java.lang.reflect.Method.invoke(Method.java:564) ~[na:na]
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.framework.adapter.MethodBeforeAdviceInterceptor.invoke(MethodBeforeAdviceInterceptor.java:52) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:174) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:92) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:689) ~[spring-aop-5.0.5.RELEASE.jar!/:5.0.5.RELEASE]
        at io.github.candyleer.prometheusdemo.PrometheusDemoApplication$$EnhancerBySpringCGLIB$$87a9d754.springTest(<generated>) ~[classes!/:0.0.1-SNAPSHOT]
        at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]

after enhanced by cglib,it seems that cannot find the method in class io.github.candyleer.prometheusdemo.PrometheusDemoApplication$$EnhancerBySpringCGLIB$$5772d178
so i fixed by fetch the original class which mean io.github.candyleer.prometheusdemo.PrometheusDemoApplication through Method method = ReflectionUtils.findMethod(pjp.getTarget().getClass(), name, parameterTypes);
it works.

@brian-brazil
Copy link
Copy Markdown
Contributor

Can you add a unittest for this?

@candyleer
Copy link
Copy Markdown
Author

candyleer commented Apr 16, 2018

@brian-brazil ok,wait a moment ,i think i should use a proxy class to test this
and i update the code by search method by

Method method = ReflectionUtils.findMethod(pjp.getTarget().getClass(), name, parameterTypes);

cause in cglib mode,the method exist in parent class,not the target class

@candyleer
Copy link
Copy Markdown
Author

unit test has been added.

@brian-brazil
Copy link
Copy Markdown
Contributor

@andrewstuart Would you mind taking a look at this?

@andrewstuart
Copy link
Copy Markdown
Contributor

Whoops, just saw this notification. Sure thing!

Copy link
Copy Markdown
Contributor

@andrewstuart andrewstuart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this looks good to me, and seems like it should handle the use case better.

@brian-brazil
Copy link
Copy Markdown
Contributor

Great.

Can you add the DCO please?

candyleer added 5 commits April 21, 2018 15:24
Signed-off-by: candyleer <[email protected]>
Signed-off-by: candyleer <[email protected]>
Signed-off-by: candyleer <[email protected]>
Signed-off-by: candyleer <[email protected]>
@candyleer candyleer force-pushed the fix_aop_no_class_defined branch from c18646b to 9ac1179 Compare April 21, 2018 07:29
@candyleer
Copy link
Copy Markdown
Author

@brian-brazil DCO has been added for all histories commit and check passed

@brian-brazil brian-brazil merged commit ad17a8f into prometheus:master Apr 23, 2018
@brian-brazil
Copy link
Copy Markdown
Contributor

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants