我正在使用aspectj,并且定义了两个几乎相同的方面,无论第二个在编译过程中是否失败,第一个都可以正常工作,如下所示:
[WARNING] advice defined in com...RolesAspect has not been applied [Xlint:adviceDidNotMatch]
第一方面:
@Aspect
public class RoleAspect {
@Before("requireRolePointcut(requireRole)")
public void requireRole(JoinPoint joinPoint, RequireRole requireRole) throws Throwable {
//TODO
}
@Pointcut("@annotation(requireRole)")
public void requireRolePointcut(RequireRole requireRole) {
}
}
第二方面:
@Aspect
public class RolesAspect {
@Before("requireRolesPointcut(requireRoles)")
public void requireRoles(JoinPoint joinPoint, RequireRoles requireRoles) throws Throwable {
//TODO
}
@Pointcut("@annotation(requireRoles)")
public void requireRolesPointcut(RequireRoles requireRoles) {
}
}
Annotation RequireRole:
@Retention(RetentionPolicy.RUNTIME)
@Target(value={ElementType.METHOD})
public @interface RequireRole {
String value();
}
Annotation RequireRoles:
@Retention(RetentionPolicy.RUNTIME)
@Target(value={ElementType.METHOD})
public @interface RequireRoles {
String[] value();
}
非常感谢您的帮助。我尝试了许多不同的注释,但是第二个注释始终失败,因此可能必须包含一些注释。
方面没有失败,您看到的只是一个AspectJ编译器警告,告诉您切入点不match。
不幸的是您没有显示
因此,现在,我只能告诉您修复切入点以使其与您要拦截的内容相匹配-或编辑您的问题以向我显示并提出评论。然后,我可以再看看并提供更多具体提示。