spring - 我们可以使用 Spring-AOP 去掉 Aspects 的 bean 定义吗?

标签 spring spring-aop aop

我的方面如下:

@Aspect
public class SomeAspect{
    //define pointcuts
    // define Advices pertaining to pointcuts
}

我的方面配置 xml 文件:
<?xml ...?>
  <beans ...
   xmlns:aop
   xmlns:context ..>
      <bean id="someAspect" class="...SomeAspect"/>
      <aop:aspectj-autoproxy />

  </beans>

这运行得很好

我需要什么:

我想在我的配置 xml 文件中摆脱为每个方面编写 bean 定义,如上所示。

我尝试了以下操作:

已添加 @ComponentSomeAspect并在 xml 添加 <context-component-scan>带有包含我的 Aspect 的相应包,希望我的类(class)被选为 Bean 和 Aspect。
然而,我的方面根本没有被接受。

任何指针?

最佳答案

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

看看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>

我认为您尝试过的方法会奏效,但是如果没有完全按照您的方式看到它,就很难确定。

关于spring - 我们可以使用 Spring-AOP 去掉 Aspects 的 bean 定义吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14166103/

相关文章:

java - AspectJ inside(is(FinalType)) 丢失

c# - 内核的组件容器中没有注册过这样的组件

java - Spring AOP 与多线程

spring - Java Spring Eclipse Tomcat - RestTemplate,使用 HTTPS API

hibernate - 我应该先学习什么,Spring 还是 Hibernate?

java - Spring Ws 客户端中的基本身份验证

java - Spring Integration 没有为端点定义轮询器

java - 无法将 Spring 方面设置为最低顺序

java - 需要 Spring 源工具帮助

java - 使用方面注释将类型间声明从 .aj 转换为 .java