<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智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                **1. AspectJ框架** AspectJ 是一個獨立的 AOP 框架,Spring 整合了該框架來實現注解式的 AOP 編程。 ``` ====常用的 AOP 注解==== @Order(int value) 決定切面對象其作用的順序,value越小越先被執行 @Aspect 將切面對象注入IoC容器中 @Pointcut 定義切入點 @Before 前置增強 @After 最終增強 @AfterReturning 后置增強 @AfterThrowing 異常增強 @Around 環繞增強 ``` <br/> **2. AOP注解使用步驟** (1)在`resources/ApplicationContext.xml`中開啟AspectJ代理和包掃描。 ```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 https://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 http://www.springframework.org/schema/aop/spring-aop.xsd"> <!--開啟包掃描--> <context:component-scan base-package="com.learn.spring06.*" /> <!-- 開啟AspectJ代理 --> <aop:aspectj-autoproxy /> </beans> ``` (2)目標對象。 ```java @Service public class StudentServiceImpl implements StudentService { @Override public void add(int x, int y) { System.out.println("------目標函數的輸出------\n" + (x + y)); } } ``` (3) 創建切面對象。 ```java @Component @Aspect @Order(1) // 該注解可選 public class AspectLogger { private static final Logger logger = Logger.getLogger(AspectLogger.class); @Before("execution(* com.learn.spring.annotation.service..*.*(..))") public void printLogger(JoinPoint jPoint) { logger.info("\n------增強函數的輸出------" + "\n增強方式:前置增強" + "\n目標對象:" + jPoint.getTarget() + "\n目標函數:" + jPoint.getSignature().getName() + "\n目標函數的參數:" + Arrays.toString(jPoint.getArgs())); } } ``` 切入點還可以如下編寫: ```java // 寫法1 @Before("execution(* com.learn.spring.annotation.service.impl.StudentServiceImpl.add(..))") public void printLogger(JoinPoint jPoint) {...} // 寫法2:先封裝切入點,再應用到增強函數中 @Pointcut(value = "execution(* com.learn.spring.annotation.service.impl.StudentServiceImpl.add(..))") public void addStudentPointcut() {/* 封裝的切入點*/} @Before("addStudentPointcut()") public void printLogger(JoinPoint jPoint) {...} // 寫法3:可以同時配置多個切入點,使用&&或||來隔開 @Pointcut("(execution(public void add(int, int))) && (execution(public void delete())) ") public void addStudentPointcut() { /*封裝的切入點 */} @Before("addStudentPointcut()") public void printLogger(JoinPoint jPoint) {...} ``` (4)測試結果。 ``` ------增強函數的輸出------ 增強方式:前置增強 目標對象:com.learn.spring06.service.impl.StudentServiceImpl@1eb5174b 目標函數:add 目標函數的參數:[10, 20] ------目標函數的輸出------ 30 ```
                  <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>

                              哎呀哎呀视频在线观看