This is the sixth day of my participation in the More text Challenge. For details, see more text Challenge

If you have this on your resume, are familiar with Spring, and have some insight into the source code (or have read the source code), it’s inevitable to ask a few questions.

How is IOC implemented? How is the AOP underlying implementation implemented? Since these are basically interview questions, you might want to ask about some of the interfaces that Spring uses, such as what’s the difference between BeanFactory and FactoryBean?

If you’re confused, keep reading.

What is BeanFactory?

In fact, Spring source code, of course, many well-known technology source code is the same, which declared the class, interface, or variables, are able to rely on English to see the general meaning.

This is what BeanFactory is. First, it is literally a Bean factory and then, by transformation, it is a Bean container.

First look at the source code, above!

As you can see, BeanFactory is one of the most basic interfaces in Spring. It is used to define the beans and their properties. You can also see it in the source code, which contains the getBean() method that we often use during coding.

If you have seen some Spring source code, you know that there is an XmlBeanFactory class, which is called the IOC container base class, and it is also based on the BeanFactory interface, you can take a look at the source of this class; You are advised to use the Diagrams function in IDEA to view UML class Diagrams to view the relationships between various types and interfaces.

What is a FactoryBean?

Read the literal meaning first, factory Bean?

It can also be described as a factory Bean, whose responsibility is that Spring provides a way for users to instantiate the Bean by implementing the interface.

Spring also has two other ways to instantiate beans.

One is to instantiate a specific bean through its class attribute by getting the bean’s class attribute through reflection.

One is to instantiate through a configuration file.

However, neither of these methods is flexible enough, so if you want to learn more about them, please check out the source code.

To summarize

To sum up, BeanFactory and FactoryBean have nothing to do with each other except their names. I vaguely remember being confused when I was asked about them, but when I learned about them later, I found that they were.

Sure enough, the interviewer is the most skilled and wants to see if you actually read some source code.

When asked, just give two specific responsibilities and contributions to Spring, and the interviewer will probably not give you a hard time with this question.

Guys, let’s go. Like, like, like, like, like, like, like.