AspectJ Poincut用于带有指定注释的参数的方法

时间:2015-12-15 14:24:58

标签: java spring aspectj spring-aop

例如,我有以下方法:

_TIFFVSetField: ./maccrasters/prova.tif: Invalid tag "TileOffsets" (not supported by codec).
Traceback (most recent call last):
  File "getrasters.py", line 20 in <module>
    im.save(f, "TIFF")
File "C:\Python27\lib\site-packages\PIL\Image.py", line 1665, in save
  save_handler(self, fp, filename)
File "C:\Python27\lib\site-packages\PIL\TiffImagePlugin.py", line 1307, in _save
  e = Image._getencoder(im.mode, 'libtiff', a, im.encoderconfig)
File "C:\Python27\lib\site-packages\PIL\Image.py",line 430, in _getencoder
  return encoder(mode, *args + extra)

RuntimeError: Error setting from dictionary

什么是AspectJ切入点,它只针对具有@MyAnnotation注释参数的方法?

此注释可应用于方法的任何参数。

1 个答案:

答案 0 :(得分:1)

以下切入点应与您问题中方法的执行相匹配。我还提供了第二个切入点,它只是对第一个切入点的略微修改,但是如果需要匹配用注释注释的特定类型,则可能会发现它很有用。

public aspect AnnotatedMethodParameterMatchingAspect  {

    /**
     * Matches the execution of any method having a parameter annotated with the
     * {@link MyAnnotation} annotation.
     */
    pointcut executionOfMethodWithAnnotatedParameter(): 
        execution(* *(.., @MyAnnotation (*), ..));

    /**
     * Matches the execution of any method having a parameter annotated with the
     * {@link MyAnnotation} annotation where the parameter type is a {@link MyType}
     * (or a subtype).
     */
    pointcut executionOfMethodWithAnnotatedTypeRestrictedParameter(): 
        execution(* *(.., @MyAnnotation (MyType+), ..));

}