Autowired dependency not injected in Aspect in Spring MVC

前端 未结 2 688
庸人自扰
庸人自扰 2021-02-06 01:19

I am not able to @Autowire the Service Layer Instance in Aspect. In Aspect the reference to the @Autowired bean is NULL and it throws NullPointer

2条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 01:30

    See this piece of the documentation:

    7.8.3 Configuring AspectJ aspects using Spring IoC

    When using AspectJ aspects with Spring applications, it is natural to both want and expect to be able to configure such aspects using Spring. The AspectJ runtime itself is responsible for aspect creation, and the means of configuring the AspectJ created aspects via Spring depends on the AspectJ instantiation model (the 'per-xxx' clause) used by the aspect.

    The majority of AspectJ aspects are singleton aspects. Configuration of these aspects is very easy: simply create a bean definition referencing the aspect type as normal, and include the bean attribute 'factory-method="aspectOf"'. This ensures that Spring obtains the aspect instance by asking AspectJ for it rather than trying to create an instance itself. For example:

    
    

提交回复
热议问题