我有以下几个方面
@Aspect
public class AspectClass{
@DeclareParents(value="com.mac.model.*",defaultImpl=Impl.class)
public IntroduceInterface inter;
@Pointcut("execution(* com.mac.Employee.display(..))")
public void empPointcut(){}
@Before("empPointCut() && this(introduceInterface)")
public void BeforeAdvice(JoinPoint jp,IntroduceInterface inf){
inf.introMethod();
}
}
我正在尝试从spring文档中复制代码,如下所示:
@Aspect
public class UsageTracking {
@DeclareParents(value="com.xzy.myapp.service.*+", defaultImpl=DefaultUsageTracked.class)
public static UsageTracked mixin;
@Before("com.xyz.myapp.SystemArchitecture.businessService() && this(usageTracked)")
public void recordUsage(UsageTracked usageTracked) {
usageTracked.incrementUseCount();
}
}
但是它不工作它给出的错误: IllegalArgumentException错误在::0在切入点中正式取消绑定
这是一个简单的spring应用程序,.What可能是它不工作的原因吗?
发布于 2017-08-28 16:39:36
在这里输入姓名
@Before("empPointCut() && this(_name_in_here_)")
应与中相同
public void BeforeAdvice(JoinPoint jp,IntroduceInterface _name_in_here_){
所以这应该可以很好地工作:
@Aspect
public class AspectClass{
@DeclareParents(value="com.mac.model.*",defaultImpl=Impl.class)
public IntroduceInterface inter;
@Pointcut("execution(* com.mac.Employee.display(..))")
public void empPointcut(){}
@Before("empPointCut() && this(inf)")
public void BeforeAdvice(JoinPoint jp,IntroduceInterface inf){
inf.introMethod();
}
}
发布于 2017-08-29 04:54:27
Annotation对象可通过annotation参数提供给通知。因此,这两个名称(方法参数名称和在切入点表达式中声明的注释)应该相同。
请看一下spring documentation - Passing parameters to advice中的这两部分。
来自Spring文档:
代理对象( this)、目标对象( target)和注释( @within、@target、@annotation、@args)都可以以类似的方式进行绑定。下面的示例展示了如何匹配使用@Auditable注解注释的方法的执行,并提取审计代码。
首先是@Auditable注释的定义:
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Auditable {
AuditCode value();
}
然后是与@Auditable方法的执行相匹配的建议:
@Before("com.xyz.lib.Pointcuts.anyPublicMethod() && @annotation(**auditable**)")
public void audit(Auditable **auditable**) {
AuditCode code = auditable.value();
// ...
}
https://stackoverflow.com/questions/45920565
复制相似问题