2

A fan who has worked for more than six years, went to JD.com for an interview with confidence.

Then I got stuck with a problem in Spring, sigh, I told him, 6 years later, Spring has not figured it out?

So how do you get the interviewer to pass you?

This question is: Difference between BeanFactory and FactoryBean in Spring.

Well, look at the answers of ordinary people and experts to this question.

Ordinary people:

Ok. . . . . . . . . .

Expert:

I will answer this question in several ways.

First of all, the core function of Spring is the IOC container. The so-called IOC container is essentially a Bean container or a Bean factory.

It can load and initialize beans according to the bean configuration declared in xml, and then BeanFactory can produce all kinds of beans we need.

So my understanding of BeanFactory has two.

  • BeanFactory is the top-level interface of all Spring Bean containers. It defines a set of specifications for Spring containers and provides methods like getBean to get the specified Bean instance from the container.
  • While BeanFactory generates beans, it also provides the ability to solve dependency injection between beans, which is the so-called DI.

FactoryBean is a factory bean, it is an interface, the main function is to dynamically generate an instance of a certain type of bean, that is, we can customize a bean and load it into the IOC container.

It has an important method called getObject() , which is used to realize the process of dynamically building Beans.

The OpenFeign component in Spring Cloud, the client's proxy class, is implemented using FactoryBean.

The above is my understanding of the problem.

Summarize

This question, as long as you look at the source code of the Spring framework, you can answer it.

The key is whether you are willing to push yourself to learn some technology that is not often used in your work to improve yourself.

In my opinion, salary and ability are an equivalent exchange. In a market economy, it is obviously impossible to obtain higher salary with general ability!

If you need a master interview document (with a 100,000-word interview document inside Ali) or have any technical interview questions you don't understand and want to consult, you can privately message me or leave a message in the comment area.

file

Copyright notice: All articles in this blog are licensed under CC BY-NC-SA 4.0 unless otherwise stated. Please indicate the source for Mic带你学架构 !
If this article is helpful to you, please help to follow and like, your persistence is the driving force for my continuous creation. Welcome to follow the WeChat public account of the same name to get more technical dry goods!

跟着Mic学架构
810 声望1.1k 粉丝

《Spring Cloud Alibaba 微服务原理与实战》、《Java并发编程深度理解及实战》作者。 咕泡教育联合创始人,12年开发架构经验,对分布式微服务、高并发领域有非常丰富的实战经验。