2014-06-10 1 views
0

내가 AspectJ를 함께 스칼라에서 생성자 매개 변수를 차단하기 위해 노력하고있어에서 차단 생성자 :AspectJ를이 : 스칼라

class ConstructorTest extends FlatSpecLike with Matchers { 

    "MyObjectAspect" should "work" in { 

    val t = new MyObject("leon") 

    val result = t.talk() 

    result should be("LEON") 

    } 
} 


class MyObject(text: String) { 

    def talk(): String = { 

    println(text) 

    text 

    } 
} 


@Aspect 

class MyObjectAspect { 

    @Around(value = "execution (com.leon.aop.MyObject.new(..))") 

    def constructCP(jp: ProceedingJoinPoint): AnyRef = { 

    try { 

     println("Start...") 

     val args = jp.getArgs 

     args(0) = args(0).toString.toUpperCase 

     jp.proceed(args) 

    } finally { 

     println("End...") 

    } 

    } 

} 

이 작동하지 않을 것 같다. 그러나

, 매우 유사한 자바 버전은 일할 수 :

public class AopTest { 

    @Test 
    public void test(){ 

     MyJob t = new MyJob("leon"); 

     String result = t.talk(); 

     System.out.println(result); 

     Assert.assertEquals(result, "LEON"); 

    } 

} 


public class MyJob { 

    private String text; 

    public MyJob(String value){ 
     text = value; 
    } 

    public String talk(){ 
     System.out.println(text); 
     return text; 
    } 
} 

@Aspect 

public class MyJobAspect { 

    @Around(value = "execution (com.leon.aop.MyJob.new(..))") 

    public Object constructCP(ProceedingJoinPoint jp) throws Throwable { 
     try { 

      System.out.println("Start.."); 

      Object[] args = jp.getArgs(); 

      args[0] = args[0].toString().toUpperCase(); 

      return jp.proceed(args); 

     } finally { 

      System.out.println("End..."); 
     } 

    } 

} 

누구든지 도와 드릴까요?

미리 감사드립니다. 당신은 args()를 통해 수정할 인수를 결합해야합니다

레온

답변

0

나는 내가 AspectJ를 메일 링리스트에 전에 말했다 생각한다. 내가 ML에 당신에게 말한 것을하고 어디서나 같은 질문을하는 것을 그만 두십시오. 이것은 이미 두 번째입니다. 내 조언을 무시하고 다른 곳에서 다시 묻는 것은 문제를 해결하지 않고 단지 당신을 도울 사람들을 위해 여분의 일과 여분의 문제를 만듭니다.