Spring Framework Interview Questions

6. Spring Framework

1. What is the spring framework?

Spring is an open-source design-level framework, which solves the problem of loose coupling between the business logic layer and other layers. It is a layered JavaEE one-stop lightweight open source framework.

2. The role of spring

Convenient decoupling, simplified development, AOP programming support, declarative transaction support, integrated Junit for more convenient hierarchical testing, and easy integration of various excellent frameworks

3. What is an IOC?

Inversion of control, handing over the right to create objects to spring

4. What is DI

Dependency injection of attributes. When spring creates an object through IOC, if the object has attributes, it will be assigned to it together. DI is the attribute injection of the object based on IOC.

5. Three implementations of dependency injection?

Constructor Injection, Setter Method Injection, Interface Injection

6. Explain the scope of several beans supported by Spring

a, singleton: bean has only one instance in each Spring ioc container. b, prototype: A bean definition can have multiple instances.
c. request: A bean is created for each http request, and this scope is only valid in the case of a web-based Spring ApplicationContext.
d. Session: In an HTTP Session, a bean definition corresponds to an instance. This scope is only valid in the context of a web-based Spring ApplicationContext.
e. global-session: In a global HTTP Session, a bean definition corresponds to an instance. This scope is only valid in the context of a web-based Spring ApplicationContext.
The default Spring bean scope is Singleton.

7. Transaction management types supported by Spring

a. Programmatic transaction management: This means that you manage transactions programmatically, which brings you great flexibility, but is difficult to maintain.
b. Declarative transaction management: This means that you can separate business code and transaction management, and you only need to use annotations and XML configuration to manage transactions.

8. Which type of transaction management do you prefer?

Most users of the Spring Framework choose declarative transaction management because it has the least impact on application code and is therefore more in line with the idea of ​​a non-intrusive lightweight container. Declarative transaction management is better than programmatic transaction management, albeit with a little less flexibility than programmatic transaction management (which allows you to control transactions through code).

9. Explain AOP

In the software industry, AOP is the abbreviation of Aspect Oriented Programming, which means: Aspect-Oriented Programming. A technology that achieves unified maintenance of program functions through pre-compilation and runtime dynamic agents. AOP is the continuation of OOP. Extract, insert in the way of dynamic proxy where it needs to be used. On the basis of not modifying the source code, the source code can also be enhanced before and after.

10. What is a notification? What are the five types of notifications?

A notification is an action to be done before or after a method is executed, and is actually a code segment that is triggered by the SpringAOP framework when the program is executed. Spring aspects can apply five types of advice:
a, before: pre-advice, called before a method is executed.
b, after: a notification called after the method is executed, regardless of whether the method was executed successfully or not. c, after-returning: a notification that is executed only after the method completes successfully.
d, after-throwing: The notification executed when the method throws an exception and exits. e, around: advice called before and after method execution.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325178809&siteId=291194637