Spring AOP advice is called twice

后端 未结 2 1362
我寻月下人不归
我寻月下人不归 2021-01-13 02:55

I have the following Spring AOP advice and I can\'t find out why it is called twice:

@Component
@Aspect
public class LoggingAspects {

    Logger logger = Lo         


        
相关标签:
2条回答
  • 2021-01-13 03:17

    1. hint

    Do you use JavaConfig or xml? If you're using both, it could be that the Aspect is being processed two times by the Spring IoC container.

    2. hint

    I don't annotate aspects with @Component annoation, try to remove it, maybe because of that is being processed twice by Spring.

    0 讨论(0)
  • 2021-01-13 03:17

    I found that the advice can be called twice if the aspect is declared as request-scoped. In this case the same bean is registered twice as an interceptor with different names: someAspect and scopedTarget.someAspect. I solved this issue by making the Aspect a singleton.

    Version: Spring Boot 2.0.x

    0 讨论(0)
提交回复
热议问题