I have created a spring AOP github link like below. (example1)
but in my output, I see my actual method call has not been executed. as in my first joint cut, I did not invoke proceed
but I was expecting the User method to be called as I called proceed
in the second one.
so I have the below questions
P.S1:
I tried with @Order
annotation method and class level but did not help.
P.S2: Based on @kriegaex answer here I updated my code with proceeding both joinpoints, still it is picking one only
Your aspects in example 1 are OK now, both are proceeding. But you only defined one of them as a bean in your XML configuration. Actually, I recommend to get rid of XML configuration altogether and use @Component
annotations and component scanning for your aspects and all other Spring components like controllers and services.
Anyway, just add the missing LoggingAspect2
as a bean in your config, and both aspects will be wired and executed.
<bean name="loggingAspect" class="com.luxoft.springaop.example1.LoggingAspect"/>
<bean name="loggingAspect2" class="com.luxoft.springaop.example1.LoggingAspect2"/>
A general hint for you: I think you should give your code more love. It looks a bit chaotic with regard to formatting and method naming.
To simplify aspect logging, I recommend to just log the joinpoint and maybe the aspect name for debugging/tracing purposes, if you have multiple advices targeting the same methods. Reserve elaborate text messages for cases in which you really need them. The joinpoint contains information about the type of joinpoint (always execution
in Spring AOP, only native AspectJ knows more pointcut types) and the intercepted method's signature.
Just like in my answer to your other question, I also suggest to simply use @Before
or @After
advice types instead of the more complex @Around
, because for simple logging that should be enough. No proceeding, no return values, clean and easy.