❝
As a Java programmer, Spring is a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us, a must for us. Xiaobian sorted out 50 interview questions for you, or 50 knowledge points, can be collected first 😊.
❞
1. The Spring framework?
The Spring framework was created because of the complexity of software development. Spring uses basic Javabeans to do things that were previously only possible with EJBs. For simplicity, testability, and loose coupling, most Java applications can use Spring.
2. The overall architecture of Spring?
There are about 20 modules.
3. What can Spring do?
What are the advantages of Spring? Weaknesses?
Advantages:
- Spring is a low-intrusion design.
- IOC hands over dependencies between objects to Spring, reduces coupling between components, decouples layers, and allows us to focus more on business logic.
- Provides section-oriented programming.
- Provides good integration support for various mainstream plug-ins.
- Transaction support is very good, as long as the configuration can, no manual control.
Disadvantages:
- Depends on reflection and affects performance.
5. Can you name a few new features of Spring5?
- The entire framework of spring5 is based on java8
- Support HTTP / 2
- Spring Web MVC supports the latest apis
- Spring WebFlux responsive programming
- Support for Kotlin functional programming
6.IOC?
Responsible for creating objects, managing them (through dependency injection), consolidating them, configuring them, and managing their life cycles.
7. What is dependency injection?
Dependency injection (DI) is an important way for Spring to implement IoC, shifting control of dependencies between objects from the developer to the container.
8. What are the ways of IOC injection?
Constructor injection
2. The setter injection
3. Interface injection (we hardly use it)
9. The IOC advantages? Weaknesses?
Advantages:
- Decoupled components improve program maintainability and flexibility.
Disadvantages:
-
Object creation is complicated and has some learning costs.
-
Using reflection to create objects is inefficient. (In terms of flexibility and maintainability of code, Spring has made our development a lot easier, which is a small loss.)
10. Bean life cycle?
1.Spring instantiates the bean.
2.Spring injects the value and a reference to the bean into the bean’s corresponding properties.
3. If the bean implements the BeanNameAware interface, Spring passes the bean ID to the setBeanName() method.
4. If the bean implements the BeanFactoryAware interface, Spring calls the setBeanFactory() method, passing in a reference to the bean’s application.
5. If the bean implements the ApplicationContextAware interface, Spring calls the setApplicationContext() method, passing in the bean’s application reference.
6. If the bean implements the BeanPostProcessor interface, the Spring will call them in the post – ProcessBeforeInitalization () method.
7. If the bean implements the InitializingBean interface, Spring will call their after-propertiesSet () method, which is similarly called if the bean has declared an initialization method using init-method.
8. If the bean implements the BeanPostProcessor interface, Spring will call their post – ProcessAfterInitialization () method.
9. At this point, the beans are ready to be used by the application, and they will reside in the application context until the application is destroyed.
10. If the bean implements the DisposableBean interface, Spring will call its deStory () interface method, which will also be called if the bean declares a destruction method with destroy-method.
11. How many ways can Spring be configured?
- Based on XML
- Based on the annotation
- Based on Java
12. How many scopes do beans in Spring have?
- Singleton: Singleton, where only one object instance is created per bean.
- Each invocation of the bean request generates its own instance.
- Request, request, generates a new bean for each HTTP request. The value is valid in a single HTTP request.
- Session. In an HTTP session, a bean definition corresponds to a bean instance.
- Global Session: In a global HTTP session, a bean definition corresponds to a bean instance.
13. What is AOP(faceted Programming)?
In the software industry, AOP for the abbreviation of Aspect Oriented Programming, meaning: section-oriented Programming, through pre-compilation and runtime dynamic proxy to achieve unified maintenance of program functions of a technology.
14. How many types of notifications are there on a slice? Is respectively?
Before: Call notification Before the target method is called.
After: call After the target method completes.
Post-returning Notification: Notification is called After successful execution of the target method.
After-throwing: Calls notifications After the target method throws an exception.
Around notification: Performs custom behavior before and after a notified method invocation.
15. What is a Join point?
A join point is a point at which an aspect can be inserted during application execution. This point can be when a method is called, when an exception is thrown, or even when a field is modified.
16. What is a Pointcut?
The definition of the pointcut matches one or more join points that the advice is woven into. We usually specify these pointcuts using either explicit class and method names, or regular expressions that define matching class and method names. Some AOP frameworks allow us to create dynamic pointcuts where we can decide whether or not to apply advice based on run-time decisions, such as method parameter values.
What is an Aspect?
A section is a combination of notification and pointcut. Together, notifications and pointcuts define the entire content of the aspect.
18. Weave (has)?
Weaving is the process of applying a facet to a target object and creating a new proxy object. The section is woven into the target object at the specified join point.
19. Introduction?
Imports allow us to add new methods or attributes to existing classes.
20. Are there multiple points in the target object’s life cycle that can be woven into?
- Compile time: The aspect is woven in when the target class is compiled. AspectJ’s weaving compiler weaves facets in this way.
- Class loading time: The aspect is woven when the target class is loaded into the JVM. It enhances the bytecode of a target class before it is introduced into the application. AspectJ 5’s load-time Weaving (LTW) supports weaving into sections in this way.
- Run-time: Facets are woven in at some point during the application run. Typically, the AOP container dynamically creates a proxy object for the target object when weaving into the cut. Spring AOP is woven into the facets in this way.
AOP dynamic proxy strategy?
- If the target object implements the interface, JDK dynamic proxies are used by default. You can force a switch to CgLib to implement AOP.
- If no interface is implemented, CgLib is used for dynamic proxy.
22. What is an MVC framework?
The full name of MVC is Model View Controller, which is the abbreviation of Model, View and Controller. It is a Model of software design. It organizes code by separating business logic, data and interface display, and gathers business logic into one component. There is no need to rewrite business logic while improving and customizing interfaces and user interactions.
MVC has been uniquely developed to map traditional input, processing, and output functions in a logical graphical user interface structure.
23. What is SpringMVC?
SpringMVC is a module of the Spring framework. Is an MVC based framework.
24. The core of SpringMVC?
DispatcherServlet
25. How many components of SpringMVC?
DispatcherServlet: Front-end controller, also known as central controller. It schedules all related components.
HandlerMapping: a processor mapper that maps to different handlers based on the URL path.
HandlerAdapter: A processor adapter that executes the Handler according to the rules of the HandlerAdapter.
Handler: The processor that we develop ourselves according to the business.
ViewResolver: a ViewResolver that parses a logical view into a concrete view.
View: An interface whose implementation supports different View types (freeMaker, JSP, etc.)
26.SpringMVC workflow?
1. The first stop on the user request journey is the DispatcherServlet.
2. After receiving the request, the DispatcherServlet invokes HandlerMapping to obtain the corresponding Handler.
3. Return if there is an interceptor.
4. After getting the Handler, find the HandlerAdapter to access the Handler and execute the Handler.
5. Run the Handler logic.
6.Handler returns a ModelAndView object to the DispatcherServlet.
7. Return the obtained ModelAndView object to the DispatcherServlet.
8. Request the ViewResolver to parse the View into a real View according to the logical View name.
9. Return View to DispatcherServlet.
10.DispatcherServlet renders the View.
11.DispatcherServlet responds to user.
27. Advantages of SpringMVC?
1. Features of Spring.
2. Supports multiple views (JSP, Freemaker), etc.
3. Easy configuration.
4. Non-intrusive.
5. Clearer layers, easier to maintain and readable code developed by the team.
Jsp is rarely used today.
28. Are singleton beans thread-safe?
It isn’t. Specific threading issues need to be addressed by the developer.
29. From what two perspectives does Spring implement autowiring?
Component scanning :Spring automatically discovers beans created in the application context.
Autowiring :Spring automatically satisfies dependencies between beans.
30. How many ways are there for automatic assembly? Is respectively?
No – The default setting, indicating that there is no automatic assembly.
ByName: assembly byName.
ByType: assembly byType.
Constructor: Automatically assembs other beans of the same type as the Bean’s constructor input parameter into the corresponding Bean constructor input parameter.
Autodetect: Try constructor assembly first, and then byType when it fails.
Default: the value is determined by the default-Autowire attribute of the parent label.
31. How many annotations declare beans?
- @Component
- @Service
- @Repository
- @Controller
Inject Java collection tags?
- The same values are allowed.
- No identical values are allowed.
- Both key and value must be strings.
- < map > keys and values can be of any type.
33.“ORM supported by Spring“?
-
Hibernate
-
iBatis
-
JPA (Java Persistence API)
-
TopLink
-
JDO (Java Data Objects)
-
OJB
34. @ Repository comments?
The Dao layer implements class annotations and scans registered beans.
35. @ Value comments?
Inject constants, configuration variable values, etc into variables.
36. @ Controller notes?
Define the controller class.
37. Which is to declare a facet annotation?
@Aspect
38. What are the annotations for mapping web requests?
@RequestMapping
39. @ ResponseBody notes?
The effect is to convert the return object to the top format, via the appropriate converter, into the body section of the Response. Usually used to return JSON, XML, etc.
40.@ResponseBody + @Controller =?
@RestController
41. Which annotation is used for the receive path parameter?
@PathVariable
42. @ Cacheable notes?
Used to mark cached queries.
43. Which annotation is clearing the cache?
@CacheEvict
44. @ Component annotation?
A general term for a component that is difficult to categorize.
45.“The BeanFactory and ApplicationContext“The difference between them?
46. @ the Qualifier annotations?
When creating multiple beans of the same type and you want to assemble only one of them with a property, you can use the @Qualifier annotation and the @AutoWired annotation to eliminate confusion by specifying which actual bean will be assembled.
47. What are the transaction annotations?
@Transactional
What are the implementation methods of Spring transactions?
Declarative: Declarative transactions can also be implemented in two ways.
- XML configuration file.
- Annotation mode (add the @Transaction annotation to the class).
Encoding format: Provides a coded form for managing and maintaining transactions.
49. What is transaction propagation?
How transactions propagate in nested method calls, and how they propagate, depends on the transaction propagation behavior.
50. What are the Spring transaction propagation behaviors?
Reference:
-
Spring in Action 4
-
Inside SPRING Technology
-
Deep Parsing of Spring source code
-
“Spring5 Enterprise development Combat”
-
https://spring.io
-
Baidu encyclopedia
This article is formatted using MDNICE