- 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.
- Learning PostgreSQL
- Visual FoxPro程序設計教程
- Python數據可視化:基于Bokeh的可視化繪圖
- 深入淺出Java虛擬機:JVM原理與實戰
- 單片機C語言程序設計實訓100例:基于STC8051+Proteus仿真與實戰
- Practical Data Science Cookbook(Second Edition)
- Unity Virtual Reality Projects
- RTC程序設計:實時音視頻權威指南
- 好好學Java:從零基礎到項目實戰
- Mastering Web Application Development with AngularJS
- AngularJS UI Development
- 前端架構設計
- Python繪圖指南:分形與數據可視化(全彩)
- R語言:邁向大數據之路
- Java Web 從入門到項目實踐(超值版)