Spring Aop Error Can not build thisJoinPoint lazily for this advice(Spring AOP错误无法懒惰地为此建议构建thisJoinPoint)
问题描述
切入点声明:
@Pointcut(value="com.someapp.someservice.someOperation() && args(t,req)",argNames="t,req")
private void logOperationArg(final String t,final String req)
{
}
建议声明未编译:
@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(JoinPoint jp, final String t, final String req){
...
}
使用AspectJ-maven-plugin(1.5版)编译方面时,出现错误"can not build thisJoinPoint lazily for this advice since it has no suitable guard [Xlint:noGuardForLazyTjp]"
但编译相同的建议时不使用JoinPoint参数。
建议声明汇编:
@Before(value="logOperationArg(t,req)")
public void logBeforeOperationAdvice(final String t, final String req){
...
}
推荐答案
Spring AOP
仅支持method join points
,因为它基于dynamic proxies
在需要时创建代理对象(例如,如果您使用的是ApplicationContext,则它将在从BeanFactory
加载Bean后创建)
使用execution()
语句匹配作为方法执行的连接点。
例如:
class LogAspect {
@Before("execution(* com.test.work.Working(..))")
public void beginBefore(JoinPoint join){
System.out.println("This will be displayed before Working() method will be executed");
}
现在如何声明您的BO:
//.. declare interface
然后:
class BoModel implements SomeBoInterface {
public void Working(){
System.out.println("It will works after aspect");
}
}
execution()
语句是PointCut表达式,用于告知应将建议应用于何处。
如果您喜欢使用@PointCut
,可以这样做:
class LogAspect {
//define a pointcut
@PointCut(
"execution(* com.test.work.SomeInferface.someInterfaceMethod(..))")
public void PointCutLoc() {
}
@Before("PointCutLoc()")
public void getBefore(){
System.out.println("This will be executed before someInterfaceMethod()");
}
}
第2部分:
此外,该错误还表明您没有保护您的建议。从技术上讲,Guard使您的代码更快,因为您不需要在每次执行它时都构造thisJoinPoint。因此,如果没有意义,您可以尝试忽略它
canNotImplementLazyTjp = ignore
multipleAdviceStoppingLazyTjp=ignore
noGuardForLazyTjp=ignore
这篇关于Spring AOP错误无法懒惰地为此建议构建thisJoinPoint的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Spring AOP错误无法懒惰地为此建议构建thisJoinPoin


基础教程推荐
- 如何在 JFrame 中覆盖 windowsClosing 事件 2022-01-01
- 多个组件的复杂布局 2022-01-01
- 验证是否调用了所有 getter 方法 2022-01-01
- 在 Java 中创建日期的正确方法是什么? 2022-01-01
- 从 python 访问 JVM 2022-01-01
- 如何在 Spring @Value 注解中正确指定默认值? 2022-01-01
- 不推荐使用 Api 注释的描述 2022-01-01
- 大摇大摆的枚举 2022-01-01
- Java Swing计时器未清除 2022-01-01
- Java 实例变量在两个语句中声明和初始化 2022-01-01