@Aspect
@Component
public class YjzAspect {
@Before(value = "execution(public void com.yjz.service.UserService.test(..)) && args(a,b)",argNames = "a,b")
public void before(JoinPoint joinPoint,String a,String b){
System.out.println(a);
System.out.println(b);
System.out.println("方法前执行");
}
}
@Component
public class UserService {
public void test(String a,String b){
System.out.println("test");
}
}
public class Test {
public static void main(String[] args) {
// 创建一个Spring容器
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(AppConfig.class);
UserService userService = (UserService) applicationContext.getBean("userService");
userService.test("a","b");
}
}
执行结果: