我们可以使用Spring-AOP摆脱Aspects的bean定义

Vik*_*ram 5 aop spring spring-aop

我的观点如下:

@Aspect
public class SomeAspect{
    //define pointcuts
    // define Advices pertaining to pointcuts
}
Run Code Online (Sandbox Code Playgroud)

我的aspect-config xml文件:

<?xml ...?>
  <beans ...
   xmlns:aop
   xmlns:context ..>
      <bean id="someAspect" class="...SomeAspect"/>
      <aop:aspectj-autoproxy />

  </beans>
Run Code Online (Sandbox Code Playgroud)

这完全没问题

我需要的是:

我想摆脱每个Aspect的写bean定义,如上面的config xml文件中所示.

我尝试了以下方法:

增加了@ComponentSomeAspect在XML中添加<context-component-scan>含我的方面希望我的课被拿起作为一个Bean并作为看点相应的包装物.但是,我的看点根本没有被提升.

有什么指针吗?

nic*_*ild 4

context:component-scan元素有一个子元素,您可以使用它来包含注释类以供扫描拾取。

查看该context:include-filter元素及其属性。

<context:component-scan base-package="my.package.to.scan">
    <context:include-filter type="annotation" expression="org.aspectj.lang.annotation.Aspect"/>
</context:component-scan>
Run Code Online (Sandbox Code Playgroud)

我认为你尝试过的方法会起作用,但是如果没有完全按照你所做的那样看到它,就很难确定。