- 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.
- DevOps:軟件架構(gòu)師行動(dòng)指南
- Extending Jenkins
- Hyper-V 2016 Best Practices
- Rust實(shí)戰(zhàn)
- Django:Web Development with Python
- Python機(jī)器學(xué)習(xí):手把手教你掌握150個(gè)精彩案例(微課視頻版)
- Learning OpenStack Networking(Neutron)
- Learning JavaScript Data Structures and Algorithms
- Building Machine Learning Systems with Python(Second Edition)
- Java Web開(kāi)發(fā)就該這樣學(xué)
- Kivy Cookbook
- C語(yǔ)言程序設(shè)計(jì)與應(yīng)用(第2版)
- Django 5企業(yè)級(jí)Web應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)(視頻教學(xué)版)
- Android應(yīng)用開(kāi)發(fā)實(shí)戰(zhàn)(第2版)
- 零基礎(chǔ)C#學(xué)習(xí)筆記