spring實現aop

<!-- AOP配置 -->
<aop:config>
<!-- 配置切點表達式 相似註解的重用表達式-->
<aop:pointcut expression="execution( com.cana.dc.service.UserService..Login(..))"
id="pointcut"/>
<!-- 配置切面及通知 method的值就是 loggerAspect類中的值-->
<aop:aspect ref="aopAspect" >
<aop:before method="beforeAdvice" pointcut-ref="pointcut"/>
<!--<aop:after method="afterAdvice" pointcut-ref="pointcut"/>-->
<!--<aop:after-returning method="afterRunningAdvice" pointcut-ref="pointcut" returning="result"/>-->
<!--<aop:after-throwing method="afterThrowingAdvice" pointcut-ref="pointcut" throwing="exception"/>-->
</aop:aspect>
</aop:config>
//==========================================================express

@Component
public class AopAspect {ide

public void beforeAdvice(JoinPoint joinPoint) {
    User user = (User)joinPoint.getArgs()[0];
    System.out.println("參數轉換成user");
    System.out.println("target對象地址"+joinPoint.getTarget());
    System.out.println("this對象地址"+joinPoint.getThis());
}

}this

相關文章
相關標籤/搜索