2017-07-26 113 views
0

我做了一個簡單的java項目來測試ByteBuddy。我輸入完全相同的代碼由拉斐爾溫特做了一個教程,但它顯示我加字節好友-1.7.1.jar作爲參考圖書館借了一些錯誤如何在java項目中使用ByteBuddy

1) ByteBuddyAgent cannot be resolved. 
    2) type cannot be resolved to a variable. 
    3) builder cannot be resolved. 
    4) method cannot be resolved to a variable. 

public class LogAspect { 

public static void main(String[] args){ 
    premain("", ByteBuddyAgent.installOnOpenJDK()); 
    Calculator calculator = new Calculator(); 
    int sum = calculator.sum(10, 15, 20); 
    System.out.println("Sum is "+ sum); 
} 

public static void premain(String arg, Instrumentation inst){ 

    new AgentBuilder.Default() 
    .rebase(type -> type.getSimpleName().equals("Calculator")) 
    .transform((builder, typeDescription) -> builder 
      .method(method -> method.getDeclaredAnnotations().isAnnotationPresent(Log.class)) 
      .intercept(MethodDelegation.to(LogAspect.class).andThen(SuperMethodCall.INSTANCE))) 
      .installOn(inst); 
} 


public static void intercept(@Origin Method method){ 
    System.out.println(method.getName()+" is called."); 
} 

} 

@interface Log{ 

} 

class Calculator { 
@Log 
public int sum(int... values) { 

    return Arrays.stream(values).sum(); 
} 

} 

回答

0

它看起來像你正在使用一個非常過時的0. * ara教程。使用IDE檢查編譯時錯誤,並使用check the webpage獲取更新的教程。

相關問題