[英]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.