您的位置:首页 > 编程语言 > Java开发

关于Spring Aop,日志功能简单的实现

2017-03-18 13:37 495 查看
在Spring自定义xml文件中加入以下代码

  xmlns:aop="http://www.springframework.org/schema/aop"

  http://www.springframework.org/schema/aop  http://www.springframework.org/schema/aop/spring-aop.xsd"
<!-- 自动代理类 -->

<aop:aspectj-autoproxy ></aop:aspectj-autoproxy>

以下是具体的切面类

需要一个aspectjweaver架包

@Service

@Aspect

public class Logrecord {

@Before("pointCut()")

 public void  before(){
SimpleDateFormat ss=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String ssql1= ss.format(new Date()); 
String log="日志记录开始"+ssql1;
System.out.println(log);

 } 

 //自定义切入 动态切入 静态切入   

@Pointcut("execution(* com.*.*.*.*(..))")

private void pointCut(){}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐