Enable Spring AOP or AspectJ

若如初见. 提交于 2019-11-30 02:21:22
MikePatel

@Component will create 2 instances, one inside the Spring container, one inside the aspectJ container.

use @Configurable to allow spring to manage dependency injection etc. for your class when instantiated by the aspectj container.

@Aspect is an aspectj style annotation that is supported by spring-aop, where runtime weaving is used to handle interception etc.

Compile-time weaving allows you to disregard the use of as pointcuts will be present in the bytecode, this is done via the aspectj compiler (See https://www.mojohaus.org/aspectj-maven-plugin/ for mvn integration) .

Whether you use the aspectj compiler or spring-aop makes no difference, it wont create your aspect as a managed bean in the way you want unless you use factory / configurable.

Aspectj configuration is, strictly, the pointcut definitions etc that will be present inside your class.

@Aspect is not a spring annotation, and it is not detected by component-scan. So you have to register it somehow as a spring bean. The aspectOf solution works. You can also try

@Aspect
@Component

Use

  • @Aspect
  • @Configurable

Also add "< context:spring-configured />" in your XML configuration file.

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