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

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                # Spring AOP – 切面順序 > 原文: [https://howtodoinjava.com/spring-aop/spring-aop-specifying-aspects-ordering/](https://howtodoinjava.com/spring-aop/spring-aop-specifying-aspects-ordering/) 在上一個教程中,我們了解了 [**spring aop 關鍵術語和示例**](https://howtodoinjava.com/spring/spring-aop/spring-aop-aspectj-example-tutorial-using-annotation-config/) 。 這些我們創建了一個日志記錄切面,然后應用于`UserManager`類。 假設您的應用程序中有多個切面,并且可以將它們應用于某種方法。 如果將多個切面應用到同一個連接點,除非您使用`@Order`注解或`org.springframework.core.Ordered`接口明確指定了切面,否則將不會確定這些切面的優先級/順序。 在這個例子中,我們將看到一個有序切面的例子。 ## 指定切面順序 如前所述,要指定切面的順序,您有兩種方法: **1)使用`@Order`注解指定**切面的排序 這很簡單。 使用如下注解。 ```java @Aspect @Order(0) public class EmployeeCRUDTransactionAspect { @Before("execution(* EmployeeManager.getEmployeeById(..))") public void getEmployeeById(JoinPoint joinPoint) { System.out.println("EmployeeCRUDTransactionAspect.getEmployeeById() : " + joinPoint.getSignature().getName()); } } @Aspect @Order(1) public class EmployeeCRUDLoggingAspect { @Before("execution(* EmployeeManager.getEmployeeById(..))") public void logBefore(JoinPoint joinPoint) { System.out.println("EmployeeCRUDAspect.logBefore() : " + joinPoint.getSignature().getName()); } } ``` **2)通過實現`org.springframework.core.Ordered`接口**指定切面排序 這太容易了。 ```java @Aspect public class EmployeeCRUDLoggingAspect implements Ordered { //Override this method public int getOrder() { return 0; } @Before("execution(* EmployeeManager.getEmployeeById(..))") public void logBefore(JoinPoint joinPoint) { System.out.println("EmployeeCRUDAspect.logBefore() : " + joinPoint.getSignature().getName()); } } @Aspect public class EmployeeCRUDTransactionAspect implements Ordered { //Override this method public int getOrder() { return 1; } @Before("execution(* EmployeeManager.getEmployeeById(..))") public void getEmployeeById(JoinPoint joinPoint) { System.out.println("EmployeeCRUDTransactionAspect.getEmployeeById() : " + joinPoint.getSignature().getName()); } } ``` 現在該測試順序是否有效。 在`applicationContext.xml`文件中配置兩個切面。 ```java <aop:aspectj-autoproxy /> <context:component-scan base-package="com.howtodoinjava.demo.aop" /> <bean id="transactionAspect" class="com.howtodoinjava.demo.aop.EmployeeCRUDTransactionAspect" /> <bean id="loggingAspect" class="com.howtodoinjava.demo.aop.EmployeeCRUDLoggingAspect" /> ``` 讓我們運行以下示例: ```java public class TestAOP { @SuppressWarnings("resource") public static void main(String[] args) { ApplicationContext context = new ClassPathXmlApplicationContext("com/howtodoinjava/demo/aop/applicationContext.xml"); EmployeeManager manager = context.getBean(EmployeeManager.class); manager.getEmployeeById(1); } } Output: EmployeeCRUDAspect.logBefore() : getEmployeeById EmployeeCRUDTransactionAspect.getEmployeeById() : getEmployeeById Method getEmployeeById() called ``` 很棒。 **Spring AOP 切面的順序**正在按預期工作。 **祝您學習愉快!**
                  <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>

                              哎呀哎呀视频在线观看