我正在尝试运行Spring in Action本书中的示例Spring AOP演示程序,以学习AOP概念。我在程序下运行时得到IllegalArgumentException。有人可以帮我了解这里有什么问题吗。
Performance.java
const GraphkManagementClient = require('azure-graph');
const client = new GraphkManagementClient(credentials, subscriptionId);
return client.users.get(principalID);
DancePerformance.java
compileSdkVersion 28
targetSdkVersion 28
buildToolsVersion 28.0.3
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:appcompat-v7:28.0.0'
CircusPerformance.java
package com.aop.annotations.example2;
public interface Performance {
public void perform() throws Exception;
}
Audience.java
package com.aop.annotations.example2;
public class DancePerformance implements Performance{
@Override
public void perform() throws Exception{
System.out.println("DancePerformance started...");
}
}
TestAOPMain.java
package com.aop.annotations.example2;
public class CircusPerformance implements Performance {
@Override
public void perform() throws Exception {
System.out.println("Circus Performance started... ");
throw new Exception("CircusException occurred");
}
}
appContext2.xml
package com.aop.annotations.example2;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.AfterThrowing;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
@Aspect
public class Audience {
@Pointcut("execution(* com.aop.annotations.example2.Performance.perform(..))")
public void performance() {
}
@Before("performance")
public void silenceCellPhones() {
System.out.println("Silence cell phones");
}
@Before("performance")
public void takeSeats() {
System.out.println("Taking seats");
}
@AfterReturning("performance")
public void applause() {
System.out.println("CLAP CLAP CLAP!!!");
}
@AfterThrowing("performance")
public void demandRefund() {
System.out.println("Demanding a refund");
}
}
例外:
package com.aop.annotations.example2;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAOPMain {
public static void main(String args[]) {
try {
ApplicationContext context = new ClassPathXmlApplicationContext("appContext2.xml");
Performance dancePerformance = context.getBean("dance", DancePerformance.class);
dancePerformance.perform();
Performance circusPerformance = (CircusPerformance) context.getBean("circus");
circusPerformance.perform();
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
}
答案 0 :(得分:0)
在性能@Before内添加(),@ AfterReturning和@AfterThrowing批注解决了该问题。
@Before("performance()")
@Before("performance()")
@AfterReturning("performance()")
@AfterThrowing("performance()")