《Spring Recipes》第三章笔记5:Pointcut Expressions

《Spring Recipes》第三章笔记5:Pointcut Expressions


Method Signature Patterns

最常用的匹配模式,根据方法的签名进行匹配。
格式:返回类型模式,方法名模式,方法参数模式还是必须的,其余的模式都可以省略不写。
execution(modifiers-pattern? return-type-pattern declaring-type-pattern? name-pattern(param-pattern)
          throws-pattern?)

如:execution(public int com.apress.springrecipes.calculator.ArithmeticCalculator.*(..))
在表达式中,使用*匹配任意字符,使用..匹配任意个参数或者任意包。

Type Signature Patterns

匹配在特定类型中定义的方法。
1、within(com.apress.springrecipes.calculator.*)匹配所有com.apress.springrecipes.calculator包中的类的方法。
2、within(com.apress.springrecipes.calculator.ArithmeticCalculatorImpl)匹配所有com.apress.springrecipes.calculator.ArithmeticCalculatorImpl中方法,如果方面和切入点在同一个包中,可以省略包名within(ArithmeticCalculatorImpl)。
3、可以在接口名后添加+来匹配所有实现了该接口的类:within(ArithmeticCalculator+)。
4、可以定义一个注解,将此注解添加到类上,然后使用within匹配这个注解:
@LoggingRequired
public class ArithmeticCalculatorImpl implements ArithmeticCalculator {
...
}

使用表达式:@within(com.apress.springrecipes.calculator.LoggingRequired)匹配ArithmeticCalculatorImpl中所有方法。

Bean Name Patterns

从Spring2.5开始,容器直接使用配置文件中定义的bean的name进行匹配。
注意:值适用于XML配置文件的AOP,不能在AspectJ注解中使用。
bean(*Calculator)

匹配所有已经Calculator结尾的bean。

Combining Pointcut Expressions

AspectJ支持通过&& (and),|| (or),和 ! (not)对表达式进行组合。

@Aspect 
public class CalculatorPointcuts {
    @Pointcut("within(ArithmeticCalculator+)")
    public void arithmeticOperation() {}

    @Pointcut("within(UnitCalculator+)")
    public void unitOperation() {}

    @Pointcut("arithmeticOperation() || unitOperation()")
    public void loggingOperation() {}
}


Declaring Pointcut Parameters

可以通过Pointcut Expressions表达式中的特殊符号获取Pointcut 对象的类型和方法参数。
使用target()获取target object,使用args()获取方法参数。
@Aspect 
public class CalculatorPointcuts {
... ...
    @Pointcut("execution(* *.*(..)) && target(target) && args(a,b)")
    public void parameterPointcut(Object target, double a, double b) {}
}


@Aspect 
public class CalculatorLoggingAspect {
... ...
    @Before("CalculatorPointcuts.parameterPointcut(target, a, b)")
    public void logParameter(Object target, double a, double b) {
        log.info("Target class : " + target.getClass().getName());
        log.info("Arguments : " + a + ", " + b);
    }
}



转载于:https://my.oschina.net/pkpk1234/blog/58262

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
《Numerical Recipes: The Art of Scientific Computing, 3rd ed.》(数字化的食谱:科学计算的艺术,第3版)是一本广受欢迎的科学计算方面的经典教材。这本书旨在教授读者如何运用数值方法解决科学研究中的各类计算问题。 第三版的《Numerical Recipes》相较于前两版做了一些重要的更新。它针对当代科学计算中的新兴领域和技术进行了全面的扩展和更新。本书包含了数值分析、插值与外插值、数值微积分、概率与统计、线性方程组与矩阵问题、特殊函数以及数值积分等内容。 这本书的特点之一是它结合了理论和实践。作者通过详细解释和讨论相应的数学理论和算法,并提供实际案例和代码示例,使读者能够迅速理解和运用这些方法。此外,书中还提供了丰富的习题和编程练习,帮助读者加深对所学知识的理解和掌握,并培养实际问题解决的能力。 作为科学计算的标准参考书,《Numerical Recipes》以其严谨的内容和广泛的应用领域而受到广泛赞誉。这本书不仅受到科学家和工程师的推崇,也常被许多大学和研究机构作为教材或参考书使用。它不仅适用于初学者,也适用于经验丰富的研究人员。 总而言之,《Numerical Recipes: The Art of Scientific Computing, 3rd ed.》是一本权威而实用的科学计算教材,它将帮助读者掌握科学计算的基本原理和方法,并提供了丰富的实例和编程练习,帮助读者应用数值方法解决各种科学计算问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值