这是一个service类:
package com.netease.course;
public class Service1 {
public void add() {
System.out.println("Service1:Add");
}
public void del() {
System.out.println("Service1:Del");
}
public void check() {
System.out.println("Service1:Check");
}
public void update() {
System.out.println("Service1:Update");
}
}
想在service类执行之前执行arithmeticDoLog函数可是最后会显示0 formal unbound in pointcut,请问应该如何解决啊!
@Aspect
public class LoggingAspect {
@Before("execution(* com.netease.course.Caculator.*())")
private void arithmeticDoLog(JoinPoint jp, int a) {
System.out.println("abc");
}
}
package com.netease.course;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestAop {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("application-context.xml");
Service1 service1 = context.getBean("service1", Service1.class);
service1.add();
service1.del();
service1.getClass();
((ConfigurableApplicationContext) context).close();
}
}
@Before("execution( com.netease.course.Caculator.())")
扫描的不对吧
表达式,和你的Service1没有关系呀