我使用aspectj和spring引導。 我想在調用方法(布爾值)時記錄消息。 方面一般工作,但我的捕捉表情一定是錯誤的帶有布爾參數的AspectJ Spring Boot catch方法
它正在與(但事業的捕捉每一個方法):
@Before("execution(* de.fhb..*(..))")
也工作(只有一個參數捕)
@Before("execution(* de.fhb..*(*))")
現在的問題:
@Before("execution(* de.fhb..*(boolean))")
Ø r
@Before("execution(* de.fhb..*(java.lang.Boolean))")
不起作用。任何幫助?這個錯誤必須執行之間(* de.fhb .. *((我的錯誤,我認爲))
這裏我的文件(吸氣& &二傳手與龍目島生成):
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.");
}
}
嘗試'java.lang.boolean'。我也懷疑創建像'setLiveTrue()'或'setLiveFalse()'這樣的方法是乾淨的代碼。它應該更像'enable()'/'disable()'或'show()'/'hide()'。但那可能只是我。 – 2014-10-28 15:10:04
java.lang.boolean給了我一個錯誤:警告沒有匹配這個類型名稱:java.lang.boolean [Xlint:invalidAbsoluteTypeName] at org.aspectj.weaver.tools.PointcutParser.parsePointcutExpression和我得到的乾淨的代碼這個想法從http://www.planetgeek.ch/wp-content/uploads/2013/06/Clean-Code-V2.1.pdf(Selector/Flag Arguments)這只是一個簡單的例子(不是標準的日誌記錄,時間追蹤)。但thx爲您的建議 – svenhornberg 2014-10-28 15:35:15