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()
를 통해 수정할 인수를 결합해야합니다
레온