Spring 5 Design Patterns
上QQ阅读APP看书,第一时间看更新

Implementing the Factory design pattern in Spring Framework

Spring Framework transparently uses this Factory design pattern to implement Spring containers using BeanFactory and ApplicationContext interfaces. Spring's container works based on the Factory pattern to create spring beans for the Spring application and also manages the life cycle of every Spring bean. BeanFactory and ApplicationContext are factory interfaces, and Spring has lots of implementing classes. The getBean()method is the factory method that gives you Spring beans accordingly.

Let's see a sample implementation of the Factory design pattern.