How do spring loop dependencies work? Spring is the default singleton support loop
Dependency injection: is done at initialization time.
Initializing beans —- beans have an initialization process – the life cycle of the Spring bean- n
At what stage does the Spring bean lifecycle complete dependency injection?
Beans ——— Spring beans are lifecycle, beans must be Java objects;
Java objects —— object new out, Java objects are not necessarily beans (not in the container, no life cycle)
Quote: Spring source blog
Cycle dependencies: how to solve cycle dependencies – diagrams, tertiary caching, and cycle dependencies, SpringBean lifecycle
Spring supports cyclic dependencies by default:
Spring makes a decision during the lifecycle (bean initialization) when it instantiates the bean. The decision is made based on the property (property name: AllowCircularReferences) is true by default in Spring, and Spring provides an API to change the property name. If you do not change Spring, loop dependencies are enabled by default. Spring calls the post-processor a fourth time if the property is allowed.
2. How many ways can dependency injection be done
Constructor injection, setter method injection, interface injection; Use only constructor and setter injection;
Which dependency injection method do you recommend, constructor injection or Setter injection? You can use both methods of dependency, constructor injection and Setter injection. The best solution is to implement mandatory dependencies with constructor arguments and optional dependencies with setter methods.Copy the code
3. What configuration methods spring provides
The dependencies and services required to configure beans based on XML are specified in an XML-formatted configuration file
Annotation-based configuration you can use annotations on related class, method, or field declarations
Java API-based configuration
Spring’s Java Configuration is implemented using @Beans and @Configuration. (1) The @bean annotation plays the same role as the element. (2) The @Configuration class allows you to define dependencies between beans by simply calling other @Bean methods in the same class. Such as:
@Configuration public class StudentConfig { @Bean public StudentBean myStudent() { return new StudentBean(); }}Copy the code
How do I start annotation assembly in Spring
By default, the annotation assembly is not open in the Spring container. Therefore, to use annotation-based assembly, we must enable it in the Spring configuration file by configuring the <context: annotation-config/> element.
5. List the transaction management types supported by Spring
Spring supports two types of transaction management:
(1) Programmatic transaction management: in this process, transactions are managed with the help of programming. It gives you great flexibility, but is very difficult to maintain. Users themselves control the transaction processing logic through code. (2) Declarative transaction management: Here, transaction management is separated from business code. Use only annotations or XML-based configurations to manage transactions.
What are the implementations of AOP?
The technologies for implementing AOP fall into two main categories:
Static proxy refers to compilation using commands provided by the AOP framework so that AOP proxy classes can be generated at compile time, hence also called compile-time enhancement;
Dynamic proxies generate AOP dynamic proxy classes “temporarily” in memory at run time and are therefore also known as runtime enhancement. Includes: JDK dynamic proxy/CGLIB
7. What is the principle of how Spring transactions are implemented?
Actually the operation of the transaction was supposed to be controlled by the database, but for the convenience of users of the operation of the business logic, Spring extends the transaction features, generally we seldom use programmatic transaction, more is by adding @ Transactional annotations to implement, when adding the comments after the transaction function will automatically shut down, There is the Spring framework to help with control.
Transactional manipulation is a core aspect of AOP (via dynamic proxying). When a method is annotated with the @Transactional annotation, Spring generates a proxy object (either JDK or Cglib) based on that class, which it then uses as a bean. When using the proxy object method, if there is a transaction, then will be submitted to automatically turn off the things, then go to perform specific business logic, if there is no abnormal execution logic, then the agent logic will directly submit the current affairs, if there is any abnormal situation, then directly to a rollback operation, Of course, the user can control which exceptions are rolled back.
The life cycle of bean creation in Spring
Are Spring beans thread-safe
How are transactions implemented in Spring
What is the startup process of the Spring container
What design patterns Spring uses