我使用aspectj来拦截带注释的方法 @Profile(description="something")
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Profile {
public String description() default "";
}
@Around("com.merc.aop.ctw.aspect.PointcutDefinitions.logAnnotatedMethods(profile)")
public Object profile(ProceedingJoinPoint pjp, Profile profile) throws Throwable {
....
}
@Pointcut("@annotation(com.merc.annotations.Profile)")
protected void logAnnotatedMethods(Profile profile) {
}
Run Code Online (Sandbox Code Playgroud)
但是在使用AJC编译时我得到以下错误消息
formal unbound in pointcut
Run Code Online (Sandbox Code Playgroud)
Sea*_*oyd 20
@Pointcut("@annotation(com.merc.annotations.Profile)")
protected void logAnnotatedMethods(Profile profile) {
}
Run Code Online (Sandbox Code Playgroud)
这是不正确的,@annotation()需要参数名称,而不是参数类型.
如果使用调试代码编译类,则切入点参数必须与方法参数具有相同的名称,否则,您需要依赖参数类型是唯一的,或者使用argNames参数显式写出参数名称:
@Pointcut(value="@annotation(profile)",argNames="profile")
protected void logAnnotatedMethods(Profile arg) { }
Run Code Online (Sandbox Code Playgroud)
参考:
我在玩,发现以下工作
@Pointcut("@annotation(profile)")
protected void logAnnotatedMethods(Profile profile) {
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
30899 次 |
| 最近记录: |