1.
1.1在xml中开启aspectj的功能的支持。
<aop:aspectj-autoproxy/> 启用aspectj支持
1.2在.xml文件中配置 扫描包的
<context:component-scan base- package="com.yc.aop_xml_annotation" />
2 声明切面 : 在切面的对象中加入
@Component //IOC的
@Aspect // aspect 声明为一个切面
public class HelloAdvice {
//声明切入点:即要切入的方法.声明在服务Math类下的所有方法都使用该前置增强
@Before("execution(* com.yc.aop_xml_annotation.Math.*(..))")
public void before(JoinPoint jp) {
System.out.println("adeline ---" + jp.getSignature().getName());
}
}
4.在目标对象中声明服务
@Service("math")
public class Math {
public void hello(){
System.out.println("hello ");
}
}