M
M
mitaichik2022-01-11 18:38:30
Spring
mitaichik, 2022-01-11 18:38:30

Is there a cleaner alternative to Spring AOP?

Hello.
In Spring, you can say newbie.

You need to do a simple thing: there are a number of methods in different components.

I want to write an annotation that would transparently change the behavior of the method to this:

- would call the contents of the method
- if the exception - would try to call again, and so on several attempts
- if the specified number of attempts failed - call the last exception
- if the call was successful - return the result

I have a lot of similar methods in the code.

As I understand it, conceptually it seems to be suitable for Spring AOP (I have not dealt with it yet).
The configuration at first glance is complicated, but you can figure it out.
The most confusing thing is that in the aspect you need to specify attachment points of the type

@Pointcut("execution(public * com.example.demoAspects.MyService.*(..))")


This is a pain - I would just like to add an annotation to the method, but if you need to prescribe somewhere else - someone will definitely mess up, forget.

Is there an easier way to implement this functionality?
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2022-01-11
@sergey-gornostaev

Such an annotation already exists in Spring.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question