FactoryBean
A factory bean in Spring serves as a factory for creating other beans within the Spring IoC container. A FactoryBean is an interface that you, as a developer, implements when writing factory classes and you want the object created by the factory to be managed as a bean by Spring.
In Java terms we can say that, a factory bean is very similar to a factory method (Java Factory Pattern).
But here it is Spring specific bean which can be identified by the Spring IoC container during bean construction.
Factory is mostly used to implement framework specific operations.
1. Suppose when you are looking for JNDI related stuffs then JndiObjectFactoryBean can be used.
2. For Spring AOP related stuffs (create a proxy for a bean) we can use ProxyFactoryBean.
3. For creating Hibernate Session Factory in the Spring IoC container then we can use LocalSessionFactoryBean.
Difference between BeanFactory and FactoryBean in Spring Framework
本文介绍了Spring框架中的FactoryBean概念及其用途。FactoryBean是Spring特定的Bean类型,用于创建和管理其他Bean。它常用于实现框架特定的操作,如通过JndiObjectFactoryBean获取JNDI资源、使用ProxyFactoryBean实现Spring AOP以及利用LocalSessionFactoryBean创建Hibernate SessionFactory等。

2238

被折叠的 条评论
为什么被折叠?



