An overview of the

This chapter focuses on Spring FAQ and interpretation of these questions.

Q&A

Spring Ioc

  1. What does Spring Ioc mean?

Ioc is one of the many features of the Spring Framework. It stands for inversion of control, and the process of inversion is to give Spring Ioc the job of creating objects that we would otherwise need to do with new. Spring Ioc helps us complete these actions. In addition to object creation, Ioc also has a function to implement object initialization assignment.

  1. Core parameters of BeanDefinition?

BeanDefinition is basically the Bean definition information. Spring uses ASM bytecode technology to read the.class file and then get the BeanDefinition of the Bean and pass it Define beans as metadata for objects. Contains Bean property values, constructor parameter values, and concrete method implementations. Allows BeanFactoryPostProcessors to modify and assignment.

  1. What is a BeanPostProcessor?

BeanPostProcessor is the core interface of Spring Framework extension, through Which DI and AOP can be implemented. Commonly used two classes have AutowiredAnnotationBeanPostProcessor automatic injection and DefaultAdvisorAutoProxyCreator achieve automatic proxy AOP

  1. How to start the Spring Ioc container?

1). Initialize a Reader and Scanner, Reader can be used to register a single BeanDefinition, Scanner can be used to scan BeanDefinition 2). Register the configuration class as a BeanDefinition 3 via Reader. Call the refresh method to start the Spring container 4). Get a Bean factory 5). Pre-add some Bean post-processors to the Bean factory, some singleton beans, and some other configuration 6). Execute the Bean factory’s post-processor, where a scan is performed, scanning the Bean and its post-processor 7). Instantiate the bean’s post-processor and sort it, then add it to the bean factory 8). Initialize the MessageSource used for internationalization 9). Initialize the event broadcaster 10). Register event listeners 11). Start instantiating non-lazy-loaded singleton beans 12). Publish the ContextRefreshedEvent event

Circular dependencies

  1. Why does @AutoWired implement circular dependencies but constructors do not?

First, Spring Ioc creates objects in two core steps, object creation and property initialization. The process of Bean initialization requires the creation of objects first. If loop dependency is implemented through constructors, it will result in an infinite loop when two objects are created at the same time as each other.

  1. Do two FactoryBeans support circular dependencies?

support

Spring Aop

  1. How does Spring AOP understand it?

An Aop karyotype is an extension of the functionality that implements object behavior, such as before, after, or when an exception occurs. Additional logic is added to this process, usually using Aop mechanisms to implement permission control, logging, caching, and transaction processing

  1. What are the most important elements of AOP?

Advice (execution timing and execution content), join points (points during execution at which cuts can be inserted), pointcuts (where to insert them), and cuts (advice + pointcuts) weave in

  1. @aspect what are the most important steps?

AnnotationAwareAspectJAutoProxyCreator to handle @ Aspect. Determine in the wrapIfNecessary method whether the proxy is needed and that the advice with those proxies has completed the creation of the proxy object

  1. @before@afterreturing these why not need to show the call XXX.

@ Before @ AfterReturing interceptors are respectively AspectJAfterAdvice AspectJAfterThrowingAdvice rewrite the MethodInterceptor# invoke method, And actively calls XXX. Venerated () in the method.

Spring source code

  • Spring Startup Process
  • The life cycle of Spring beans
  • Spring property injection
  • Spring loop dependencies
  • Spring Aop
  • Spring transactions
  • Spring integration MyBatis
  • Spring FAQ