從aop的概念和術語開始.這些術語不是spring特有的.不幸的是,這些術語不是特別直觀;然而,如果使用spring自己的術語,將會更加混亂.
* Aspect切面:橫切多個類的模塊化內容.事務管理是一個很好的例子,在spring aop中切面符合xml的模版或使用注解@Aspect 兩種實現方式.
* Join point連接點:執行過程中的一個點,例如執行方法或處理異常.在spring aop中總是代表方法執行
* Advice建議:一個切面在連接點處執行.不同的建議包括 "around", "before" and "after" .許多aop框架,包括spring,建議的模型就是攔截器,在連接點處維護攔截器鏈.
* Pointcut切點:連接點的詳細描述.切點表達式和建議關聯在一起,在任何匹配切點的連接點上執行(如明確的執行方法名稱).匹配切點表達式的連接點概念是aop的核心,spring默認使用AspectJ 切點表達式語言.
* Introduction引入:聲明其他方法或屬性作為一個類型.spring aop允許你為建議的對象引入一個新的接口和實現.例如,使用引入使bean實現`Introduction`接口,簡化緩存.
* Target object:目標對象:被一個或多個切面建議的對象,也表示建議對象本身.由于Spring AOP是使用運行時代理實現的,因此此對象將始終是代理對象。
* AOP proxy代理:aop框架創建的對象實現了切面的約束(建議方面執行等).在spring框架中,aop代理就是jdk動態代理或者CGLIB 代理
* Weaving編織:把切面和應用的其他類型或對象鏈接到一起來創建建議對象.這個編織過程可以在編譯期,加載期或運行期.spring aop和其他純java的aop框架一樣,在運行期編織.
Types of advice:
* Before advice:建議在連接點之前執行,但是它沒有能力阻止執行流程進入連接點(除非它拋出異常)。
* After returning advice:建議在連接點正常結束之后執行:例如方法return沒有拋出異常
* After throwing advice:建議在方法拋出異常退出的時候執行
* After (finally) advice: 建議在連接點退出后執行,無論正常合適異常,都執行
* Around advice: 建議包圍連接點如方法調用執行.這是非常強大的建議類型.在方法執行前后分別執行.它還負責選擇是繼續執行連接點還是通過返回自己的返回值或拋出異常來繞過方法的執行。
Around advice是最通用的建議類型,由于spring aop像AspectJ一樣,提供了所有的建議類型,我們強烈建議,使用最小分范圍的建議滿足需求即可.例如,你只想在方法返回結果之后更新緩存,使用After returning advice比Around advice效果更好.使用合適的建議類型,編程更簡單,減少不必要的錯誤.例如沒必要在連接點調用Around advice建議的`proceed()` 方法.也就不用考慮調用失敗的處理.
切點是aop的關鍵,區別于老舊的攔截器技術.切點能使建議獨立于面向對象的結構定位.例如around advice提供的聲明式事務管理,可以應用于跨越多個對象的一組方法(例如service層的業務方法)
- 正確打開本書的姿勢
- 第一部分 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