今天继续实现AOP,到这里我个人认为是最灵活,可扩展的方式了,就拿日志管理来说,用Spring AOP 自定义注解形式实现日志管理。废话不多说,直接开始!!!

关于配置我还是的再说一遍。

 

在applicationContext-mvc.xml中要添加的

     <mvc:annotation-driven />
     <!-- 激活组件扫描功能,在包com.gcx及其子包下面自动扫描通过注解配置的组件 -->
     <context:component-scan base-package="com.gcx" />

  

     <!-- 启动对@AspectJ注解的支持 -->
     <!-- proxy-target-class等于true是强制使用cglib代理,proxy-target-class默认是false,如果你的类实现了接口 就走JDK代理,如果没有,走cglib代理  -->
     <!-- 注:对于单利模式建议使用cglib代理,虽然JDK动态代理比cglib代理速度快,但性能不如cglib -->

     <!--如果不写proxy-target-class="true"这句话也没问题-->
     <aop:aspectj-autoproxy proxy-target-class="true"/>

     <!--切面-->
     <bean ></bean>

接下来开始编写代码。

     创建日志类实体

  1 public class SystemLog {
  2     private String id;
  3 
  4     private String description;
  5 
  6     private String method;
  7 
  8     private Long logType;
  9 
 10     private String requestIp;
 11 
 12     private String exceptioncode;
 13 
 14     private String exceptionDetail;
 15 
 16     private String params;
 17 
 18     private String createBy;
 19 
 20     private Date createDate;
 21 
 22     public String getId() {
 23         return id;
 24     }
 25 
 26     public void setId(String id) {
 27         this.id = id == null ? null : id.trim();
 28     }
 29 
 30     public String getDescription() {
 31         return description;
 32     }
 33 
 34     public void setDescription(String description) {
 35         this.description = description == null ? null : description.trim();
 36     }
 37 
 38     public String getMethod() {
 39         return method;
 40     }
 41 
 42     public void setMethod(String method) {
 43         this.method = method == null ? null : method.trim();
 44     }
 45 
 46     public Long getLogType() {
 47         return logType;
 48     }
 49 
 50     public void setLogType(Long logType) {
 51         this.logType = logType;
 52     }
 53 
 54     public String getRequestIp() {
 55         return requestIp;
 56     }
 57 
 58     public void setRequestIp(String requestIp) {
 59         this.requestIp = requestIp == null ? null : requestIp.trim();
 60     }
 61 
 62     public String getExceptioncode() {
 63         return exceptioncode;
 64     }
 65 
 66     public void setExceptioncode(String exceptioncode) {
 67         this.exceptioncode = exceptioncode == null ? null : exceptioncode.trim();
 68     }
 69 
 70     public String getExceptionDetail() {
 71         return exceptionDetail;
 72     }
 73 
 74     public void setExceptionDetail(String exceptionDetail) {
 75         this.exceptionDetail = exceptionDetail == null ? null : exceptionDetail.trim();
 76     }
 77 
 78     public String getParams() {
 79         return params;
 80     }
 81 
 82     public void setParams(String params) {
 83         this.params = params == null ? null : params.trim();
 84     }
 85 
 86     public String getCreateBy() {
 87         return createBy;
 88     }
 89 
 90     public void setCreateBy(String createBy) {
 91         this.createBy = createBy == null ? null : createBy.trim();
 92     }
 93 
 94     public Date getCreateDate() {
 95         return createDate;
 96     }
 97 
 98     public void setCreateDate(Date createDate) {
 99         this.createDate = createDate;
100     }
101 }
View Code

相关文章: