使用布尔参数的AspectJ Spring Boot catch方法

时间:2014-10-28 14:49:27

标签: java spring aop spring-aop

我使用aspectj和spring boot。 我试图在调用方法(布尔值)时记录消息。 方面正在发挥作用,但我的表达方式一定是错误的

它正在使用(但是有理由抓住每种方法):

    @Before("execution(* de.fhb..*(..))")

也在工作(仅使用一个参数)

    @Before("execution(* de.fhb..*(*))")

现在出现了问题:

    @Before("execution(* de.fhb..*(boolean))")

    @Before("execution(* de.fhb..*(java.lang.Boolean))")

不起作用。有帮助吗?错误必须在执行之间(* de.fhb .. *((我的错误我认为))

这里我的文件(getter&& setter是用lombok生成的):

POJO:

package de.fhb.showcase;

@Getter @Setter
public class Show {

    private String name;
    private boolean live;

    public void makeShowLive(boolean value) {
        live = value;
    }
}

方面:

package de.fhb.aop;

import javax.inject.Named;

import lombok.extern.java.Log;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;

@Aspect
@Named
@Log
public class CleanCodeAspect {

    @Before("execution(* de.fhb..*(..))")
    public void checkStyleBooleanParameter() {

        log.warning("You used a method with only one boolean parameter. "
                + "Refactor it into 2 methods with True, False at the end.");
    }

}

1 个答案:

答案 0 :(得分:0)

您的语法是正确的,请在没有Lombok的情况下查看并测试自己。我认为问题是Lombok干扰了AspectJ,可能与描述here类似(按照那里的链接了解更多细节)。这可能是另一个问题,但这将是我的第一个赌注。

相关问题