<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>

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                **1.配置相關-applicationContext.xml** ~~~ <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context https://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop.xsd"> <!--指定包和該包下的子包,掃描注解--> <context:component-scan base-package="com.nobb"/> <!--開啟注解配置切面開關--> <aop:aspectj-autoproxy/> </beans> ~~~ **2.使用注解注冊通知對象-com.nobb.advice.MyAdvice** ~~~ package com.nobb.advice; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component; /** * 通知 */ //交給spring管理 并命名為myAdvice //<bean name="myAdvice" class="com.nobb.advice.MyAdvice"></bean> @Component("myAdvice") //聲明在該類中配置切面 @Aspect public class MyAdvice { //聲明切點 @Pointcut("execution(* com.nobb.service.*ServiceImpl.*(..))") public void myPc(){ } //切點+前置通知 @Before("myPc()") public void before(){ System.out.println("前置通知"); } //切點+后置通知 @AfterReturning("myPc()") public void after(){ System.out.println("后置通知"); } //切點+異常通知 @AfterThrowing("myPc()") public void afterThrowing(){ System.out.println("異常通知"); } //切點+最終通知 @After("myPc()") public void end(){ System.out.println("最終通知"); } //環繞通知, @Around("execution(* com.nobb.service.*ServiceImpl.*(..))") public Object around(ProceedingJoinPoint pjp){ Object o = null; try{ System.out.println("環繞通知-前置"); //執行業務代碼 o = pjp.proceed(); System.out.println("環繞通知-后置"); }catch(Throwable throwable){ throwable.printStackTrace(); System.out.println("環繞通知-異常"); }finally{ System.out.println("環繞通知-最終"); } return o; } } ~~~ **3.UserServiceImpl** ~~~ package com.nobb.service; import org.springframework.stereotype.Service; //將UserServiceImpl 交給spring管理 并命名為userService @Service("userService") public class UserServiceImpl implements UserService { @Override public void save() { System.out.println("save()"); } @Override public void delete() { System.out.println("delete()"); } @Override public void update() { System.out.println("update()"); } @Override public void find() { System.out.println("find()"); } } ~~~ **4.測試代碼** ~~~ import com.nobb.service.UserService; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import javax.annotation.Resource; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("classpath:applicationContext3.xml") public class AopTest { @Resource(name="userService") private UserService userService; @Test public void fun1(){ userService.save(); } } ~~~
                  <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>

                              哎呀哎呀视频在线观看