How to Autowire members reliably inside an Aspect - even after a context refresh?

淺唱寂寞╮ 提交于 2019-12-05 19:57:37

I've have often wondered why they don't make it easier for spring to manage the aspect.

But to make the aspect spring managed you put the following into your xml... Don't know how you'd do it with java configuration.

Though I think configuration should work as well... although you may have issues with life cycle conflicts.

<bean id="securityAspect" 
   class="com.afrozaar.ashes.core.security.AuthorizationAspect"> 
   factory-method="aspectOf" autowire="byType" />

When the aspect compiler creates an aspect it adds that "aspectOf" method to the class. This method gives access to the object that is the aspect and having this config in your xml will expose that object to injection etc by spring.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!