<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [上一篇博客](http://blog.csdn.net/gaopeng0071/article/details/47106039),我們學習了基于注解配置AOP。 下面我們基于XML來配置AOP。 看代碼 ~~~ public interface Calculation { public int add(int x, int y); public int sub(int x, int y); public int mul(int x, int y); public int dev(int x, int y); } ~~~ ~~~ public class CalculationImpl implements Calculation { @Override public int add(int x, int y) { int result = x + y; System.out.println("executeing ..."); return result; } @Override public int sub(int x, int y) { int result = x - y; return result; } @Override public int mul(int x, int y) { int result = x * y; return result; } @Override public int dev(int x, int y) { int result = x / y; System.out.println("executeing ..."); return result; } } ~~~ ~~~ public class CalculationAspect { public void afterReturnMethod(JoinPoint joinPoint, Object ret) { String name = joinPoint.getSignature().getName(); List<Object> list = Arrays.asList(joinPoint.getArgs()); System.out.println("@AfterReturning ... ,method=" + name + ", args = " + list + ", return = " + ret); } public Object aroundMethod(ProceedingJoinPoint pjd) { String name = pjd.getSignature().getName(); List<Object> list = Arrays.asList(pjd.getArgs()); Object obj = null; System.out.println("前置通知 ... ,method=" + name + ", args = " + list); try { obj = pjd.proceed(); System.out.println("返回通知 ... ,method=" + name + ", args = " + list); } catch (Throwable e) { System.out.println("異常通知 ... , exception = " + e); e.printStackTrace(); } System.out.println("后置通知 ... ,method=" + name + ", args = " + list); return obj; } } ~~~ 第一個切入方法,我們其中有后置返回通知、環繞通知兩個方法。 ~~~ public class ValidateAspect { public void validate(){ System.out.println("驗證方法 com.gp.spring.aop.impl.ValidateAspect"); } } ~~~ 第二個切入方法。 ~~~ public class ValidateAspect { public void validate(){ System.out.println("驗證方法 com.gp.spring.aop.impl.ValidateAspect"); } } ~~~ ~~~ <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:cache="http://www.springframework.org/schema/cache" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.1.xsd http://www.springframework.org/schema/cache http://www.springframework.org/schema/cache/spring-cache-4.1.xsd"> <bean id="calculationImpl" class="com.gp.spring.aop.impl.xml.CalculationImpl"></bean> <bean id="calculationAspect" class="com.gp.spring.aop.impl.xml.CalculationAspect"></bean> <bean id="validateAspect" class="com.gp.spring.aop.impl.xml.ValidateAspect"></bean> <aop:config> <aop:pointcut expression="execution(public int com.gp.spring.aop.impl.xml.Calculation.*(int, int))" id="pointcut" /> <aop:aspect ref="calculationAspect" order="1"> <aop:after-returning method="afterReturnMethod" pointcut-ref="pointcut" returning="ret" /> <aop:around method="aroundMethod" pointcut-ref="pointcut" /> </aop:aspect> <aop:aspect ref="validateAspect" order="2"> <aop:before method="validate" pointcut-ref="pointcut" /> </aop:aspect> </aop:config> </beans> ~~~ 核心的東西來了 這里我們用XML配置代理了注解 ![這里寫圖片描述](https://box.kancloud.cn/2016-03-15_56e7afc1c7d4e.jpg "") 執行測試方法 ~~~ public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext-xml.xml"); Calculation calculation = (Calculation)context.getBean("calculationImpl"); int result = calculation.add(1, 3); System.out.println(result); } ~~~ 輸出結果 ~~~ 前置通知 … ,method=add, args = [1, 3] 驗證方法 com.gp.spring.aop.impl.ValidateAspect executeing … @AfterReturning … ,method=add, args = [1, 3], return = 4 返回通知 … ,method=add, args = [1, 3] 后置通知 … ,method=add, args = [1, 3] 4 ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看