"Spring Volume 18 of "Interview Eight-Part Essay" It's freshly released again. This time I have sorted out the interview questions about spring. I also looked through the interview questions about spring online and summarized them. , the basics are all here. Of course, there may be some concepts that are too basic. I have directly organized them into a certain question, so I have not opened a separate question. I wish everyone a smooth interview~
1.What design patterns are used in spring?
2.What are the core modules in spring?
3. Tell me what you understand by IOC?
4.What are the IOC containers in spring? What are the differences?
5. What is the difference between BeanFactory and FactoryBean?
6. What is the difference between @Repository, @Service, @Compent, and @Controller?
7. So what is DI?
8. What is AOP?
- ##9. What is the difference between dynamic proxy and static proxy?
- 10. What is the difference between JDK dynamic proxy and CGLIB proxy?
- 11.What is the difference between Spring AOP and AspectJ AOP?
- 12.What is the life cycle of Bean in spring?
- 13.How does spring solve circular dependencies?
- 14. Why use third-level cache? Can’t the second-level cache solve it?
- 15. What is the difference between @Autowired and @Resource?
- 16.What are the transaction isolation levels of spring?
- 17.What are the propagation mechanisms of spring transactions?
- 18.springBoot automatic assembly principle?
1.What design patterns are used in spring?

『1.Factory Design Pattern』: For example, producing Bean objects through BeanFactory and ApplicationContext 『2.Agent Design Pattern』: AOP The implementation method is through proxy. Spring mainly uses JDK dynamic proxy and CGLIB proxy 「3. Singleton design pattern」: Bean in Spring The default is singleton 「4. Template method mode」: In Spring, jdbcTemplate and other classes ending with Template that operate on the database will use templates Method design pattern, some common functions 「5. Wrapper design pattern」: Our project needs to connect to multiple databases, and different customers need to connect to each database. During each visit, different databases will be accessed as needed.This mode allows us to dynamically switch between different data sources according to customer needs 「6. Observer Mode」: Spring event-driven model observer mode ’s 「7. Adapter Mode」: Spring AOP’s enhancement or notification (Advice) uses the adapter mode
2.What are the core modules in spring?

1.「Spring Core": Spring core, which is the most basic part of the framework, provides IOC and dependency injection DI features 2."Spring Context": Spring Context container, which is a sub-interface with enhanced functionality of BeanFactory 3.「Spring Web」: It provides support for Web application development 4.「Spring MVC」: It is aimed at the implementation of MVC ideas in Web applications 5.「Spring DAO」: Provides a JDBC abstraction layer, simplifying JDBC coding, and at the same time, the coding is more robust 6.「Spring ORM」: It supports Integration of popular ORM frameworks, such as: Spring Hibernate, Spring iBatis, Spring JDO integration, etc. 7.「Spring AOP」: Aspect-oriented programming, It provides a programming implementation compatible with the AOP Alliance
3. Tell me what IOC you understand?

First of all, IOC is a "container" , which is used to load objects. Its core idea is "Inversion of Control"
So what exactly"What is inversion of control"?
Inversion of control means,"Give control of the object to spring and manage it by the spring container 』, we will not perform any operations
Then why"What needs inversion of control"?
Let's imagine that when there is no inversion of control, we need"to create objects and configure objects ourselves" , and "manually handle various complex dependencies between objects" , when a project is scaled up, the maintenance of this relationship is very troublesome. So there is the concept of inversion of control, which leaves a series of operations such as object creation and configuration to spring for management. When we use it, we just need to get it
4.What are the IOC containers in spring? What are the differences?
spring mainly provides "two IOC containers" , one is "BeanFactory" ", there is another one is "ApplicationContext"
The difference between them is that BeanFactory "only provides the most basic functions of instantiating objects and getting objects" , and ApplicationContext is a product derived from BeanFactory and is its subclass. Its function is more powerful, such as supporting annotation injection, internationalization and other functions
5. What is the difference between BeanFactory and FactoryBean?
These two are "different products"
"BeanFactory is IOC Container" is used to carry objects
"FactoryBean is an interface", which provides a more flexible way for Bean. By proxying a Bean object, the method can be processed before and after. some operations.
6. What are the differences between @Repository, @Service, @Compent and @Controller?
of these four annotations "The essence is the same. The object identified by the annotation is put into the spring container, just to distinguish different application layers in use"
@Repository:dao layer @Service:service layer @Controller:controller layer @Compent: Other components that do not belong to the above three layers use this annotation
7. Then DI What is it?
DI is dependency injection. In fact, it is roughly the same as IOC, but "the same concept is explained from different angles"
What DI describes"The focus is on dependence", we said"The core function of IOC is to dynamically provide other dependent objects to an object when the program is running", This function is accomplished by relying on DI. For example, if we need to inject an object A, and this object A depends on an object B, then we need to inject this object B into object A. This is dependency injection
## There are three injection methods in #spring- Interface injection
- Constructor injection
- set injection
8. What is AOP?
AOP means:"Aspect-oriented programming, A technology that achieves unified maintenance of program functions through precompilation and dynamic proxies during runtime".
AOP is"The continuation of OOP (Object-Oriented Programming)". It is an important content in the Spring framework and a derivative paradigm of functional programming. AOP can be used to isolate various parts of business logic, thereby reducing the coupling between various parts of business logic, improving program reusability, and improving development efficiency.
「AOP implementation is mainly divided into two categories:」
「Static AOP implementation」, AOP framework「During the compilation phase」Modify the program source code, A static AOP proxy class is generated (the generated *.class file has been changed and a specific compiler needs to be used), such as AspectJ "Dynamic AOP Implementation" , AOP framework "at runtime" For dynamically generating proxy objects (using JDK dynamic proxy in memory, or dynamically generating AOP proxy classes using CGlib), such as SpringAOP
The implementation of AOP in spring is "implemented through dynamic proxy". If the interface is implemented, the JDK dynamic proxy will be used, otherwise the CGLIB proxy will be used.

「There are 5 notification types:」
「@Before」: Notify before the target method is called ##「@AfterReturning」: Call after the target method returns or exceptions 『@AfterThrowing』: Called after the target method returns 『@After』: Called after the target method exceptions 『@Around』: Encapsulate the target method and determine the calling time yourself
9. What is the difference between dynamic proxy and static proxy?
「Static proxy」
Created by programmers or automatically generated by specific tools, and then compiled. Before the program is run, the .class file of the proxy class already exists Static proxies usually only proxy one class Static proxies know in advance What to proxy
"Dynamic proxy"
When the program is running, it is dynamically created using the reflection mechanism. Cheng Dynamic proxy is a proxy for multiple implementation classes under an interface Dynamic proxy does not know what to proxy, only at runtime Only then did I know
10. What is the difference between JDK dynamic proxy and CGLIB proxy?
JDK dynamic proxy business class "must implement a certain interface" , which is "implemented based on a reflection mechanism" , and generates an implementation A proxy class of the same interface, and then enhances the code by overriding methods.
CGLIB dynamic proxy uses the bytecode processing framework ASM. Its principle is to use bytecode technology to "create a subclass for a class, and then override the method of the parent class", to achieve Enhancements to the code.
11.What is the difference between Spring AOP and AspectJ AOP?
Spring AOP is a run-time enhancement, which is implemented through"dynamic proxy implementation"
AspectJ AOP is a compile-time enhancement, which requires a special compiler. Completion is achieved by"modifying the code", and supports "three weaving methods"
「Compile-time weaving」: It is to weave related proxy classes into the bytecode when compiling the bytecode "Weaving after compilation": After compiling the initial class, it is found that AOP enhancement is needed, and then the relevant code is woven into it "Weaving when the class is loaded" : refers to weaving when the loader loads the class.

Spring AOP | AspecjtJ AOP | |
---|---|---|
Run-time enhancement | Compile-time enhancement | |
Dynamic proxy | Modify code | |
javac | Special compiler ajc | |
Lower (runtime reflection loss performance) | Higher | |
Runtime | Compile time, after compilation, class loading time |
The above is the detailed content of 'Interview Eight-Part Essay' Spring Volume 18. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 English version
Recommended: Win version, supports code prompts!

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver Mac version
Visual web development tools