???????????
1 package com.test;
2
3 import java.util.List;
4
5 public interface TestService {
6     public void test(String testStr??int age??List list);
7 }
?????????????
1 package com.test;
2
3 import java.util.List;
4
5 public class TestServiceImpl implements  TestService{
6     public void test(String testStr?? int age?? List list) {
7         // TODO Auto-generated method stub
8         System.out.println("test TestServiceImpl");
9     }
10 }
??????????????
1 package com.test;
2
3 import org.aspectj.lang.JoinPoint;
4 import org.aspectj.lang.annotation.After;
5 import org.aspectj.lang.annotation.AfterThrowing;
6 import org.aspectj.lang.annotation.Aspect;
7 import org.aspectj.lang.annotation.Before;
8 import org.aspectj.lang.annotation.Pointcut;
9 import org.springframework.stereotype.Component;
10
11
12 @Aspect
13 @Component
14 public class LogAspect {
15
16     /**
17      * execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) throws-pattern?)
18         1.modifiers-pattern??????????????
19         2.ret-type-pattern???????
20         3.declaring-type-pattern????????????
21         4.name-pattern????????
22         5.parm-pattern????????
23         6.throws-pattern????
24         ???????ret-type-pattern??name-pattern?????????????????????У?execution(* com.spring.service.*.*(..))???com.spring.service???£??????????????????????????????????????????з?????
25      */
26
27     private  final String cutValue = "execution(public * com.test.*.*.*(..))";
28
29     /**
30      * ?????????
31      * @param jp
32      * @throws Exception
33      */
34     @Before(cutValue)
35     public void beforeShow(JoinPoint jp) {
36 //            HttpServletRequest request = ((ServletRequestAttributes) (RequestContextHolder.getRequestAttributes())).getRequest(); //((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
37 ////        ?????IP
38 //            String ip = request.getRemoteAddr();
39 //            System.out.println("????ip?????"+ip);
40 //            String className = jp.getThis().toString();
41 //            System. out.println("====λ???" +className);
42             String sName = jp.getTarget().getClass().getName();
43             System.out.println("????????"+sName);
44             String methodName = jp.getSignature().getName();   //??÷?????
45             System. out.println("?????÷?????" +methodName);
46             Object[] args = jp.getArgs();  //??ò????б?
47             for (Object object : args) {
48                 System. out.println("????????? ????"+object);
49             }
50             System. out.println("??" +jp.getSignature().getName()+"??????????????");
51
52     }
53
54     /**
55      * ???ú?????
56      * @param jp
57      */
58     @After(cutValue)
59     public void afterShow(JoinPoint jp) {
60         System. out.println("??" +jp.getSignature().getName()+"?????????y?????");
61    }
62
63     /**
64      * Service ?е?
65      * ??????????÷?????????壬????????????????????????????????????
66      */
67     @Pointcut(cutValue)
68     public void aspectExecption(){    }
69
70    /**
71     * ???????????????????????aspectExecption()???????????
72     * @param jp
73     * @param ex
74     */
75     @AfterThrowing(pointcut = "aspectExecption()"?? throwing = "ex")
76      public  void doAfterThrowing(JoinPoint jp?? Throwable ex) {
77         System.out.println("??"+jp.getSignature().getName()+"?????????"+ex);
78     }
79 }