您好,欢迎来到爱问旅游网。
搜索
您的当前位置:首页Spring中的AOP

Spring中的AOP

来源:爱问旅游网
使用Spring中的AOP的流程: 1、实现业务(登陆)

2、编写方面代码(方面:日志)

package com.springtest;

import java.lang.reflect.Method; import java.text.SimpleDateFormat; import java.util.Date;

import org.springframework.aop.MethodBeforeAdvice; public class LogAdvice implements MethodBeforeAdvice { }

3、将方面代码织入业务对象中

在添加applicationContest.xml中添加:

4.测试类

public void testSpring(){

//加载applicationContext.xml配置 ApplicationContext context=new //获取配置中的实例

UserBiz userBiz =(UserBiz)context.getBean(\"daili\");

com.springtest.biz.UserBiz

logAdvice

SimpleDateFormat sdf=new SimpleDateFormat(\"yyyy-MM-dd\"); String currentTime=sdf.format(new Date()); }

throws Throwable {

public void before(Method m, Object[] args, Object target)

String usedMethodName=m.getName(); String username=(String)args[0];

System.out.println(username+currentTime+\"调用了方法\"+usedMethodName+\" 成功

进入系统!\");

ClassPathXmlApplicationContext(\"applicationContext.xml\");

}

boolean flag=userBiz.login(\"admin\", \"123\");

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- awee.cn 版权所有 湘ICP备2023022495号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务