Copy the code

I have to say that the impact of the classical Java system to me is still relatively large. Here I do not record some implementation details of the framework, which are recorded in the notes. Here I record some core ideas and thinking of the Spring system.

 

SpringFramework

SpringFramework has two of the most important programming ideas:

  • IoC inversion of control
  • AOP is faceted oriented programming

Let’s start with the problem that these programming ideas arise to solve: decoupling!

It’s very, very important to layer our massive engineering so that each layer is focused on solving its own problems.

IoC

This is the most important idea, and turns Java development on its head.

In simple terms, a container is used to manage all bean objects.

The factory model of design thinking is used here.

All bean objects we need to use are handed over to the Spring framework for management. We use the framework to obtain and inject bean objects into each object we need through Dependency Injection.

We can easily get the objects we need through XML or annotations, and the Spring framework will inject them into each object we need.

The best way to understand IoC is that we can simply implement an IoC framework ourselves to understand IoC.

 

AOP

This is a programming mindset, not just a Framework for Java or Spring.

The advent of AOP allows each layer to focus on implementing its own functionality, while general-purpose, development-wide content such as logging, transaction security, and so on can be implemented in a single layer without having to make the entire business layer code redundant.

In the Java architecture, we implement AOP primarily through dynamic proxies.

Why are dynamic proxies so powerful? This is because we create objects at run through reflection.

This is because in Java, dynamic proxy bytecode is created as you go and loaded as you go, enhancing methods without modifying the source code.

There are two main ways:

  • The native Proxy class is used to generate Proxy objects to accomplish common tasks
  • Dynamic proxying is accomplished by implementing the proxy object through Cglib’s Enhancer

The best way to understand AOP is that we can simply implement an AOP framework ourselves to understand AOP.