- Spring 5 Design Patterns
- Dinesh Rajput
- 179字
- 2021-07-08 09:59:31
Implementing the Abstract factory design pattern in the Spring Framework
In the Spring Framework, the FactoryBean interface is based on the Abstract Factory design pattern. Spring provides a lot of implementation of this interface, such as ProxyFactoryBean, JndiFactoryBean, LocalSessionFactoryBean, LocalContainerEntityManagerFactoryBean, and so on. A FactoryBean is also useful to help Spring construct objects that it couldn't easily construct itself. Often this is used to construct complex objects that have many dependencies. It might also be used when the construction logic itself is highly volatile and depends on the configuration.
For example, in Spring Framework, one of the FactoryBean implementations is LocalSessionFactoryBean, which is used to get a reference of a bean that was associated with the hibernate configuration. It is a specific configuration concerning the data source. It should be applied before you get an object of SessionFactory. You can use the LocalSessionFactoryBean to apply the specific data source configuration in a consistent way. You may inject the result of a FactoryBean's getObject() method into any other property.
Let's create a sample implementation of the Abstract Factory design pattern.
- 計算思維與算法入門
- Reporting with Visual Studio and Crystal Reports
- DevOps for Networking
- JMeter 性能測試實戰(第2版)
- 信息安全技術
- CouchDB and PHP Web Development Beginner’s Guide
- Apache Kafka Quick Start Guide
- Android系統原理及開發要點詳解
- Python語言實用教程
- Java程序設計案例教程
- Mastering Elasticsearch(Second Edition)
- 區塊鏈國產化實踐指南:基于Fabric 2.0
- H5+移動營銷設計寶典
- 微前端設計與實現
- C Primer Plus(第6版)中文版【最新修訂版】