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

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 帶有加載時織入的非公開方法上的 Spring 事務 > 原文: [https://howtodoinjava.com/spring-transaction/spring-transactions-on-non-public-methods-with-load-time-weaving/](https://howtodoinjava.com/spring-transaction/spring-transactions-on-non-public-methods-with-load-time-weaving/) 在本教程中,我們將學習如何在非公開方法上的任何 Spring 應用程序中應用事務(通過默認 [**spring AOP**](https://howtodoinjava.com/spring/spring-aop/top-spring-aop-interview-questions-with-answers/) 只能對 [IoC 容器](https://howtodoinjava.com/spring/spring-core/different-spring-3-ioc-containers-with-example/)中的 bean 的公共方法配置建議)。 使用此技術,您可以管理非公共方法的事務,也可以管理在 Spring IoC 容器外部創建的對象(即不受 IoC 容器管理)中的任何方法上的事務。 ## 使用`AnnotationTransactionAspect`管理事務 Spring 具有一個名為`AnnotationTransactionAspect`的 AspectJ 切面,它可以管理任何對象的任何方法的事務,即使這些方法是非公開的或對象是在 Spring IoC 容器外部創建的也是如此。 該切面將管理帶有`@Transactional`注解的任何方法的事務。 要啟用此有用的切面,您可以通過以下兩種方式之一來更改配置: 1. `@EnableLoadTimeWeaving`注解 2. `<context:load-time-weaver />`; 組態 #### 使用`@EnableLoadTimeWeaving`注解 必須在配置類上使用`@EnableLoadTimeWeaving`注解以在加載時獲取。 您需要做的就是定義`@EnableTransactionManagement`注解并將其`mode`屬性設置為`Aspectj`。 **切面**說,容器應使用加載時或編譯時織入來啟用事務通知。 另一個值**代理**表示容器應使用默認的 Spring AOP 機制。 請務必注意,aspect 模式不支持在接口上配置`@Transactional`注解(應僅在類上使用)。 配置示例如下所示: ```java @Configuration @EnableTransactionManagement(mode = AdviceMode.ASPECTJ) @EnableLoadTimeWeaving public class MyApplicationConfiguration { //Configuration code } ``` #### 使用`<context:load-time-weaver/>`配置 如果您在應用程序中使用了基于 XML 的配置,則可以使用以下配置更改來啟用此功能。 ```java <beans> <context:load-time-weaver /> <tx:annotation-driven mode="aspectj"/> <!-- Other beans declarations--> </beans> ``` 要啟用加載時織入,還必須包括`spring-instrument`模塊。 如果您使用的是 Maven,請將以下依賴項添加到您的項目中。 ```java <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-instrument</artifactId> <version>${spring.version}</version> </dependency> ``` 在下面將您的問題和評論丟給我。 **祝您學習愉快!** **參考**: [http://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-aj-ltw](https://docs.spring.io/spring/docs/current/spring-framework-reference/html/aop.html#aop-aj-ltw)
                  <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>

                              哎呀哎呀视频在线观看