Skip to content
Advertisement

Custom AOP spring boot annotation with ribbon client blocking api call with return “1”

I have really poor experience with ribbon/eureka so forgive me if this is a stupid question:

I have two different microservice both connected to a discovery server, the first one calls the second using a custom annotation that sends a request using rest template. Custom annotation name is PreHasAuthority

Controller :

JavaScript

Annotation interface :

JavaScript

Annotation implementation:

JavaScript

My Ribbon configuration

JavaScript

Eureka config in application properties

JavaScript

by calling the api from postman request is sendend correctly to the second microservice and i’m certain the return is “true”.

After that the request stops before entering the createUpdateRequirement method and returns ‘1’ as postman body response. No error of sort is provided.

My guess is that the problem resides within the custom annotation, cause when i remove the annotation the api call works perfectly, but i cannot understand the problem as it seems all setted up correctly to me.

Advertisement

Answer

Your @Around advice never calls joinPoint.proceed(). Hence, the intercepted target method will never be executed.

The second problem is that your advice method returns void, i.e. it will never match any method returning another type such as the ResponseEntity<?> createUpdateRequirement(..) method.

Besides, around is a reserved keyword in native AspectJ syntax. Even though it might work in annotation-driven syntax, you ought to rename your advice method to something else like aroundAdvice or interceptPreHasAuthority – whatever.

Please do read an AspectJ or Spring AOP tutorial, especially the Spring manual’s AOP chapter. ????

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement