diff --git a/spring/src/main/java/log/LoggerWithoutXml.java b/spring/src/main/java/log/LoggerWithoutXml.java new file mode 100644 index 0000000000000000000000000000000000000000..a59ad2dfb450f94c1988dab4f1622b7d46212011 --- /dev/null +++ b/spring/src/main/java/log/LoggerWithoutXml.java @@ -0,0 +1,54 @@ +package log; + +import org.aspectj.lang.annotation.*; + +/** + * @Author: fancyears·milos·malvis + * @Description: + * @Date: Created in 2019/4/28 15:01 + * @Modified By: + */ +@Aspect +public class LoggerWithoutXml { + + /** Following is the definition for a pointcut to select + * all the methods available. So advice will be called + * for all the methods. + */ + @Pointcut("execution(* bean.Parent.*(..))") + private void selectAll(){ + System.out.println("执行selectAll"); + } + /** + * This is the method which I would like to execute + * before a selected method execution. + */ + @Before("selectAll()") + public void beforeAdvice(){ + System.out.println("切点前操作"); + } + /** + * This is the method which I would like to execute + * after a selected method execution. + */ + @After("selectAll()") + public void afterAdvice(){ + System.out.println("切点后操作"); + } + /** + * This is the method which I would like to execute + * when any method returns. + */ + @AfterReturning(pointcut = "selectAll()", returning="retVal") + public void afterReturningAdvice(Object retVal){ + System.out.println("返回值:" + retVal.toString() ); + } + /** + * This is the method which I would like to execute + * if there is an exception raised by any method. + */ + @AfterThrowing(pointcut = "selectAll()", throwing = "ex") + public void AfterThrowingAdvice(IllegalArgumentException ex){ + System.out.println("发生异常: " + ex.toString()); + } +} diff --git a/spring/src/main/resources/Beans.xml b/spring/src/main/resources/Beans.xml index 90b36c83a6466ddc0bf47e75f888ad1e1980c198..c9d968cc9eecd6a4ee88cfb5651114c9413f5216 100644 --- a/spring/src/main/resources/Beans.xml +++ b/spring/src/main/resources/Beans.xml @@ -10,6 +10,8 @@ > + + @@ -28,7 +30,11 @@ - + + + + +