官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 始兴县| 遂平县| 罗甸县| 绥棱县| 沭阳县| 吉安市| 平顶山市| 阳信县| 城固县| 田东县| 西宁市| 平塘县| 兴化市| 宜良县| 施甸县| 定日县| 平度市| 新疆| 昌黎县| 格尔木市| 博客| 黎平县| 简阳市| 卢氏县| 信丰县| 延安市| 闻喜县| 社旗县| 蒲城县| 高淳县| 石屏县| 伊春市| 微山县| 岐山县| 青龙| 安阳县| 渭源县| 澄江县| 雷波县| 赤水市| 昭苏县|