[Interview with experts]——Spring (12 questions)

1.What is Spring?

Spring is an open source, lightweight Java application development framework. Through technologies such as Dependency Injection and Aspect-oriented Programming, developers can more easily develop scalable , modular and loosely coupled applications, greatly improving development efficiency.

2. Why do you need Spring?

Spring is an open source Java application framework that provides a way to build and manage enterprise-level applications. Spring exists for a variety of reasons, and it provides Java developers with many important benefits and capabilities, including:

  • Simplified development: The Spring framework greatly simplifies the development of Java applications. It provides many out-of-the-box features such as dependency injection, AOP (aspect-oriented programming), transaction management, etc., which can reduce the workload of developers.

  • Loose coupling: Spring encourages a loosely coupled design, making components less dependent on each other. This helps improve the maintainability, scalability, and testability of your code.

  • Dependency Injection: The Spring framework supports dependency injection (DI), making dependencies between components easier to manage. DI allows you to delegate your object's dependencies to the Spring container instead of hardcoding them in your code.

  • Aspect-oriented programming (AOP): Spring supports AOP, which allows you to separate cross-cutting concerns (such as logging, security, transaction management) from the main business logic, improving code reusability and clarity.

  • Declarative transaction management: Spring provides support for declarative transaction management, making it easier to manage database transactions. This can help ensure data consistency and reliability.

  • Integrate various technologies: Spring can be integrated with various technologies, including various persistence frameworks (such as Hibernate, JPA), message queues, Web frameworks (such as Spring MVC), security frameworks, etc.

  • Testing support: Spring is designed to make unit testing and integration testing easier. You can use Spring's testing framework to write and run tests to ensure the quality and stability of your code.

  • Modularity: The Spring framework is modular, you can choose to use only the modules you need without having to introduce the entire framework. This helps reduce application size and improve performance.

  • Community support: Spring has a large community and active development team, so there is extensive support, documentation, and tutorials.

3. Tell me your understanding of Spring’s AOP and IOC?

  • AOP: The full name of AOP is Aspect Orient Programming, which is aspect-oriented programming. It is a supplement to OOP (Object Orient Programming) and is specially used to handle some cross-cutting services. Often used for log output, security control, error handling, permission management, etc. Reduce code duplication and improve code maintainability and reusability.

  • IOC (Inversion Of Control): It is a design idea that transfers the control of objects originally created manually in the program to the Spring framework for management. Loose coupling between objects also facilitates functional reuse.

4. What are the AOP implementations based on java?

AspectJ、Spring AOP、Cglib、JBoss AOP

5.The principle of AOP?

Join point: refers to the method executed during the running of the program. In Spring AOP, a connection point always represents the execution of a method.
Aspect: The extracted common module can be used to cross-cut multiple objects. Aspect aspects can be seen as the combination of Pointcut pointcuts and Advice notifications. An aspect can be composed of multiple pointcuts and advices. In Spring AOP, aspects can be implemented on classes using the @AspectJ annotation.
Pointcut: Pointcut is used to define which Join points are to be intercepted.
Advice: refers to the action to be performed on the Join Point, that is, enhanced logic, such as permission checksums, logging, etc. There are various types of notifications, including Around, Before, After, After returning, and After throwing.
Target object (Target): The object containing the connection point, also called the object being advised (Advice). Since Spring AOP is implemented through dynamic proxy, this object is always a proxy object.
Weaving: The process of executing enhanced logic (Advice) in the method of the target object (Target) (ie, Join point) through dynamic proxy.
Introduction: Adding additional methods or fields to the advised class. Spring allows the introduction of new interfaces (and corresponding implementations) to any proxied object. For example, you can use an import to make the bean implement the IsModified interface to simplify the caching mechanism.

6. How to implement dynamic proxy using Java?

7. What is the difference between Spring AOP and AspectJ AOP?

  • Spring AOP is a runtime enhancement based on agents. AspectJ is a compile-time enhancement based on bytecode manipulation (Bytecode Manipulation).
  • AspectJ is more powerful than Spring AOP.
  • Spring AOP is relatively simple.

8.SpringAOP notification type?

  • Before Advice
  • After Advice
  • Around Advice
  • After Returning Advice
  • Exception notification (After Throwing Advice)

9. springbean life cycle

Insert image description here
Insert image description here
Spring starts, finds and loads the beans that need to be managed by Spring, and instantiates the
beans. After the beans are instantiated, inject the introduction and value of the beans into the properties of the beans
. If the beans implement the BeanNameAware interface, Spring will pass the Id of the beans to setBeanName() method
If the Bean implements the BeanFactoryAware interface, Spring will call the setBeanFactory() method and pass in the BeanFactory container instance.
If the Bean implements the ApplicationContextAware interface, Spring will call the Bean's setApplicationContext() method and reference the application context where the bean is located. Incoming in.
If the Bean implements the BeanPostProcessor interface, Spring will call their postProcessBeforeInitialization() method.
If the bean implements the InitializingBean interface, Spring will call their afterPropertiesSet() method. Similarly, if the bean declares an initialization method using init-method, this method will also be called.
If the bean implements the BeanPostProcessor interface, Spring will call their postProcessAfterInitialization() method.
At this point, the Bean is ready to be used by the application. They will remain in the application context until the application context is destroyed.
If the bean implements the DisposableBean interface, Spring will call its destroy() interface method. Similarly, if the bean uses the destroy-method to declare the destruction method, this method will also be called.

10.What is SpringMVC?

Spring MVC is part of the Spring Framework, which is a module for building Web applications. It provides a framework based on the MVC (Model-View-Controller) design pattern for developing flexible, maintainable and extensible Web app.

11.SpringMVC request process

![insert hereInsert image description here

12.What are the core components of SpringMVC?

  • DispatcherServlet (front-end controller): DispatcherServlet is the front-end controller of Spring MVC. It receives all HTTP requests and is responsible for dispatching the requests to the appropriate controller for processing. DispatcherServlet also coordinates the rendering process of views.

  • HandlerMapping (processor mapper): HandlerMapping is responsible for mapping HTTP requests to appropriate controller processing methods. Spring MVC provides a variety of HandlerMapping implementations, including RequestMappingHandlerMapping and BeanNameUrlHandlerMapping.

  • Controller: The controller is a key component in Spring MVC. It is a Java class that handles HTTP requests. Controllers contain processing methods that perform specific business logic and return model data and view names.

  • ModelAndView (model and view): ModelAndView is an object that encapsulates model data and view name. Controller methods typically return a ModelAndView containing the data to be passed to the view and the name of the view to render.

  • ViewResolver: The view resolver is responsible for resolving logical view names into actual view objects. Spring MVC supports a variety of view resolvers, such as InternalResourceViewResolver for parsing JSP views, ThymeleafViewResolver for parsing Thymeleaf templates, etc.

  • Interceptor: Interceptors allow pre- and post-processing operations to be performed during request processing. Interceptors can be applied to the entire application or to specific processors. They can be used to implement logging, permission checking, internationalization and other functions.

  • HandlerAdapter (processor adapter): HandlerAdapter is responsible for dispatching HTTP requests to the corresponding controller methods and is responsible for calling controller methods. Different types of controller methods require different adapters to handle, and Spring MVC provides a variety of adapters.

  • DataBinder: Data binding is a core feature in Spring MVC, which binds HTTP request parameters to controller method parameters. Data binding also supports data validation and type conversion.

  • View: The view is responsible for rendering model data, usually an HTML page or other response content. Spring MVC supports various view types, including JSP, Thymeleaf, FreeMarker, JSON views, etc.

  • ExceptionResolver: The exception resolver is responsible for catching and handling exceptions in the application and returning appropriate error responses. Spring MVC provides exception resolvers such as DefaultHandlerExceptionResolver and SimpleMappingExceptionResolver.

Supongo que te gusta

Origin blog.csdn.net/qq_42785250/article/details/132991873
Recomendado
Clasificación