2014-10-28 23 views
0

我使用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."); 
    } 

} 
+0

嘗試'java.lang.boolean'。我也懷疑創建像'setLiveTrue()'或'setLiveFalse()'這樣的方法是乾淨的代碼。它應該更像'enable()'/'disable()'或'show()'/'hide()'。但那可能只是我。 – 2014-10-28 15:10:04

+0

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

回答

0

你的語法是正確的,看到和自己試一試不洛美書。我認爲問題是Lombok干擾AspectJ,可能與here中描述的類似(請點擊鏈接瞭解更多細節)。這可能是另一個問題,但那將是我第一次打賭。

+0

我從我的pojo刪除lombok,但它不適用於布爾值。 *工作正常。我應該發佈鏈接到我的github回購? – svenhornberg 2014-10-28 16:22:35

+0

是的,請。我嘗試使用原生AspectJ,而不是使用Spring。我通常不是Spring用戶。 – kriegaex 2014-10-28 22:06:36

+0

在這裏使用標準樣本https://github.com/svenhornberg/spring-boot/tree/master/spring-boot-samples/spring-boot-sample-aop。我會尋找差異命名和組件不是原因 – svenhornberg 2014-10-29 12:23:55

相關問題