AOP(Aspect Oriented Programming):
被称为面向切面编程,是OOP(面向对象编程的一种补充),主要用来解决一些系统层面上的问题
AOP的三种实现方式:
1.基于Spring容器的自动代理实现AOP:
<!--被代理对象-->
<bean id="orderServiceTargetBean" class="com.apesource.service.impl.OrderServiceImpl"/>
<bean id="userServiceTargetBean" class="com.apesource.service.impl.UserServiceImpl"/>
<!--通知(Advice)-->
<bean id="logAdviceBean" class="com.apesource.LogAdvice"/>
<bean id="performanceAdviceBean" class="com.apesource.PerformanceAdvice"/>
<!--切入点(Poinecut)-->
<bean id="createPointcutBean" class="org.springframework.aop.support.JdkRegexpMethodPointcut">
<property name="pattern" value=".*create.*"/>
</bean>
<!--Advisor(高级通知) = Advice(通知) + Pointcut(切入点)-->
<bean id="performanceAdvisorBean" class="org.springframework.aop.support.DefaultPointcutAdvisor">
<!--注入通知-->
<property name="advice" ref="performanceAdviceBean"/>
<!--注入切入点-->
<property name="pointcut" ref="createPointcutBean"/>
</bean>
<!--自动代理对象-->
<bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
<!--被代理对象(目标对象)列表:根据Bean名称规则指定那些bean创建自动代理-->
<property name="beanNames">
<list>
<value>*TargetBean</value>
</list>
</property>
<!--通知列表-->
<property name="interceptorNames">
<list>
<value>logAdviceBean</value>
<value>performanceAdvisorBean</value>
</list>
</property>
</bean>
2.AspectJ技术,通过切面Aspect,基于Spring AOP的配置实现AOP:
@Before(EXPRESSION)
public void beforeAdvice(JoinPoint joinPoint){
System.out.println("=========【使用AspectJ实现前置通知