简体   繁体   English

如何使用Spring AOP来建议具有特定ID的X类bean而不是X类的所有bean

[英]How to use Spring AOP to advise a bean of class X with certain id instead of all beans of class X

In spring aop you can create advices that will effect all instance of a certain type but what I want is to advise a bean declaration not all beans of that type. 在spring aop中,您可以创建将影响某个类型的所有实例的建议,但我要建议的是建议一个bean声明,而不是该类型的所有bean。

<bean id="bean1" class="type1"/>
<bean id="bean2" class="type1"/>

I want to advise bean1 not all beans of type1 . 我想建议bean1并不是所有type1 bean。 What is the best approach? 最好的方法是什么?

From Spring Documentation regarding AOP : Spring文档中有关AOP的内容

Spring AOP also supports an additional PCD (PointCut Designator) named 'bean'. Spring AOP还支持名为“ bean”的附加PCD(PointCut指示符)。 This PCD allows you to limit the matching of join points to a particular named Spring bean, or to a set of named Spring beans (when using wildcards). 此PCD允许您将连接点的匹配限制为特定的命名Spring Bean或一组命名Spring Bean(使用通配符时)。 The 'bean' PCD has the following form: “ bean” PCD具有以下形式:

bean(idOrNameOfBean) bean(idOrNameOfBean)

The 'idOrNameOfBean' token can be the name of any Spring bean: limited wildcard support using the '*' character is provided, so if you establish some naming conventions for your Spring beans you can quite easily write a 'bean' PCD expression to pick them out. 'idOrNameOfBean'令牌可以是任何Spring bean的名称:提供了使用'*'字符的有限通配符支持,因此,如果您为Spring bean建立了一些命名约定,则可以很容易地编写一个'bean'PCD表达式来选择他们出来。 As is the case with other pointcut designators, the 'bean' PCD can be &&'ed, ||'ed, and ! 与其他切入点指定符一样,“ bean” PCD可以&&',|| ed和!! (negated) too. (否定)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Spring XML配置来设置包含特定类型的所有bean的列表的bean属性? - How can I use Spring XML configuration to set a bean property with list of all beans of a certain type? 如何在类上创建一个方面,这不是使用Spring AOP的bean? - How to create an aspect on class, that is not a bean using Spring AOP? 阅读春季3中的所有班级豆 - Read all beans of class in Spring 3 如何在Spring AOP建议中提取变量值 - How to extract a variable value in Spring AOP advise 如何从外部jar与类一起使用spring aop - How to use spring aop with class from external jar Spring延迟加载 - 加载一个bean加载该类的所有@Lazy bean - Spring lazy loading - loading one bean loads all @Lazy beans of that class 如果我在配置 class 上使用 @ActiveProfiles 注释而不是在定义我的 bean 的 class 上使用它,Spring 会发生什么? - What happens in Spring if I use the @ActiveProfiles annotation on a configuration class instead use it on the class that defines my beans? 如何在Spring bean中使用简单的类名? - How can I use the simple class name in Spring beans? org.springframework.beans.InvalidPropertyException:bean类的属性&#39;id&#39;无效 - org.springframework.beans.InvalidPropertyException: Invalid property 'id' of bean class 是否可以在不创建b​​ean的情况下使用Spring AOP? - Is it possible to use Spring AOP without creating beans?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM