[toc]
本節描述了Spring中事務傳播的一些語義。 請注意,本節不適合作為事務傳播的介紹; 相反,它詳細介紹了Spring中有關事務傳播的一些語義。
在Spring管理的事務中,要注意物理和邏輯事務之間的區別,以及傳播設置如何應用于這種差異。
## Required

### PROPAGATION_REQUIRED
`PROPAGATION_REQUIRED`強制執行物理事務:如果當前還沒有事務存在,則在本地范圍內執行,或者參與為更大范圍定義的現有“外部”事務。 這是同一線程內公共調用堆棧排列的一個很好的默認值,例如 服務外觀委托給幾個存儲庫方法,其中所有底層資源都必須參與服務級事務。
默認情況下,參與事務將使用外部作用域事務的特征,靜默忽略本地隔離級別,超時值或只讀標志(如果有)。 如果您希望隔離級別聲明在參與具有不同隔離級別的現有事務時被拒絕,請考慮在事務管理器上將“validateExistingTransactions”標志切換為“true”。 這種非寬松模式也將拒絕只讀不匹配,即內部讀寫事務試圖參與只讀外部事務的。
當傳播設置為`PROPAGATION_REQUIRED`時,將為應用該設置的每個方法創建邏輯事務范圍。 每個這樣的邏輯事務范圍可以單獨確定僅回滾狀態,外部事務范圍在邏輯上獨立于內部事務范圍。 當然,在標準`PROPAGATION_REQUIRED`行為的情況下,所有這些范圍將映射到同一物理事務。 因此,內部事務范圍中的僅回滾標記集確實會影響外部事務實際提交的機會(正如您所期望的那樣)。
然而,如果內部事務標記為回滾,而外部事務仍然提交,則外部會收到內部拋出的異常`UnexpectedRollbackException`,并內部事務已回滾.
### RequiresNew

與`PROPAGATION_REQUIRED`相反,`PROPAGATION_REQUIRES_NEW`始終對每個受影響的事務范圍使用獨立的物理事務,從不參與外部范圍的現有事務。 在這樣的安排中,底層資源事務是不同的,因此可以獨立提交或回滾,外部事務不受內部事務的回滾狀態影響,并且內部事務的鎖在完成后立即釋放。 這樣一個獨立的內部事務也可以聲明它自己的隔離級別,超時和只讀設置,從不繼承外部事務的特性。
### Nested
`PROPAGATION_NESTED`使用具有多個保存點的單個物理事務,它可以回滾到該事務。 這種部分回滾允許內部事務作用域觸發其作用域的回滾,外部事務能夠繼續物理事務,盡管已經回滾了一些操作。 此設置通常映射到JDBC保存點,因此僅適用于JDBC資源事務。 請參閱Spring的`DataSourceTransactionManager`。
- 正確打開本書的姿勢
- 第一部分 Core
- 1. Ioc container
- 1.1. Introduction to the Spring IoC container and beans
- 1.2. Container overview
- 1.2.1. Configuration metadata
- 1.2.2. Instantiating a container
- 1.2.3. Using the container
- 1.3. Bean overview
- 1.3.1. Naming beans
- 1.3.2. Instantiating beans
- 1.4. Dependencies
- 1.4.1. Dependency Injection
- 1.4.2. Dependencies and configuration in detail
- 1.4.3. Using depends-on
- 1.4.4. Lazy-initialized beans
- 1.4.5. Autowiring collaborators
- 1.4.6. Method injection
- 1.5 Bean Scopes
- 1.6. Customizing the nature of a bean TODO
- 1.7. Bean definition inheritance TODO
- 1.8. Container Extension Points TODO
- 1.9. Annotation-based container configuration
- 1.9.1. @Required
- 1.9.2. @Autowired
- 1.9.3. Fine-tuning annotation-based autowiring with @Primary
- 1.9.4. Fine-tuning annotation-based autowiring with qualifiers TODO
- 1.9.5. Using generics as autowiring qualifiers TODO
- 1.9.6. CustomAutowireConfigurer TODO
- 1.10. Classpath scanning and managed components
- 1.10.1. @Component and further stereotype annotations
- 1.11. Using JSR 330 Standard Annotations TODO
- 1.12. Java-based container configuration
- 1.12.1. Basic concepts: @Bean and @Configuration
- 1.12.2. Instantiating the Spring container using AnnotationConfigApplicationContext
- 2. Resources
- 2.1. Introduction
- 2.2. The Resource interface
- 2.3. Built-in Resource implementations
- 2.3.1. UrlResource
- 2.3.2. ClassPathResource
- 2.3.3. FileSystemResource
- 2.3.4. ServletContextResource
- 2.3.5. InputStreamResource
- 2.3.6. ByteArrayResource
- 2.4. The ResourceLoader
- 2.5. The ResourceLoaderAware interface
- 2.6. Resources as dependencies
- 2.7. Application contexts and Resource paths
- 2.7.1. Constructing application contexts
- 2.7.2. Wildcards in application context constructor resource paths
- 2.7.3. FileSystemResource caveats
- 3. Validation, Data Binding, and Type Conversion
- 4. Spring Expression Language (SpEL)
- 5. Aspect Oriented Programming with Spring
- 5.1. Introduction
- 5.1.1. AOP concepts
- 5.1.2. Spring AOP capabilities and goals
- 5.1.3. AOP Proxies
- 5.2. @AspectJ support
- 5.2.1. Enabling @AspectJ Support
- 5.2.2. Declaring an aspect
- 5.2.3. Declaring a pointcut
- 5.2.4. Declaring advice
- 5.2.5. Introductions TODO
- 5.2.6. Aspect instantiation models TODO
- 5.2.7. Example
- 5.3. Schema-based AOP support TODO
- 5.4. Choosing which AOP declaration style to use TODO
- 5.5. Mixing aspect types TODO
- 5.6. Proxying mechanisms
- 5.6.1. Understanding AOP proxies
- 5.7. Programmatic creation of @AspectJ Proxies
- 5.8. Using AspectJ with Spring applications
- 5.8.1. Using AspectJ to dependency inject domain objects with Spring
- 5.8.2. Other Spring aspects for AspectJ
- 第二部分 Testing
- 第三部分 Data Access
- 1. Transaction Management
- 1.1. Introduction to Spring Framework transaction management
- 1.2 Advantages of the Spring Framework’s transaction support model
- 1.2.1. Global transactions
- 1.2.2. Local transactions
- 1.2.3. Spring Framework’s consistent programming model
- 1.3. Understanding the Spring Framework transaction abstraction
- 1.4. Synchronizing resources with transactions
- 1.4.1. High-level synchronization approach
- 1.4.2. Low-level synchronization approach
- 1.4.3. TransactionAwareDataSourceProxy
- 1.5. Declarative transaction management
- 1.5.1. Understanding the Spring Framework’s declarative transaction implementation
- 1.5.2. Example of declarative transaction implementation
- 1.5.3. Rolling back a declarative transaction
- 1.5.4. Configuring different transactional semantics for different beans
- 1.5.5. tx:advice元素的 settings
- 1.5.6. Using @Transactional
- 1.5.7. Transaction propagation
- 1.5.8. Advising transactional operations
- 1.5.9. Using @Transactional with AspectJ TODO
- 第四部分 web servlet
- 第五部分 Web Reactive
- 第六部分 Integration
- 第七部分 Languages