Spring's understanding 3

1. Introduce spring framework related dependencies
2. Introduce spring framework configuration files
3. Through spring management components
4. Start the factory to obtain objects for testing

Spring is a factory and a project management framework (mainly responsible for the creation, use and destruction of component objects in the project)

Insert picture description here
Project management is the creation, use and destruction of components.

Insert picture description hereEntity components are generally not handed over to spring to manage

Insert picture description here
Insert picture description hereInsert picture description hereThe next step is to test whether Spring can help us create objects

The implementation class is the object created by the container for us.

The next step is to start the factory (or container) and let it create objects for us

As soon as the factory starts, as soon as it reads this configuration file, it will create component objects based on the classes we specify. And a unique identifier is given to the object created in the factory (here refers to the id)

Then we can get the objects created in the factory.

Insert picture description hereIf the object is not created to call the method, a null pointer will appear

Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description hereWe have never used the new keyword in the creation of these two objects. We all get an instance directly through parameters or servletActionContext.getRequest. (The reason you got this instance must be that someone helped us create this instance). This person is the tomcat container.

Inversion of control is found in most containers.

So Spring introduced DI

Insert picture description hereInsert picture description here
In the future, our business layer components will need to call our dao components. How do we complete the call of the components in the case of factory management?

If we want to call our dao in Dept's service, then we need to get the DeptDao component object in the service first

We need Dao components can be understood as we rely on Dao components

Insert picture description here
Dependency injection (declare it as a member variable first if you need it, the second step is to assign a value to the member variable (the process of assigning a value to a member variable is called injection),)

Insert picture description here
Insert picture description hereInsert picture description here
A property can only complete the assignment of one attribute. The name is used to specify which attribute name in the component is assigned.

Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description hereInsert picture description hereWhat ref is looking for is an object in the factory, what we want now is a string. Here we complete the assignment operation through the value attribute.
Insert picture description hereInsert picture description here
We look at the error of the framework from the bottom up

Insert picture description here
Insert picture description hereInsert picture description hereInsert picture description hereInsert picture description here
Insert picture description here

Insert picture description here

Insert picture description hereInsert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description hereInsert picture description here
Insert picture description hereThe properties collection is unordered

Insert picture description hereInsert picture description here
Insert picture description here

Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Automatic injection can only inject objects, so there must be two layers, similar to the use of Dao layer to inject business layer.

The variable is declared and the set method is set for automatic injection (byname (the variable name corresponds to the id value of the factory))

Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
The interface has the function of shielding the underlying implementation

Insert picture description hereInsert picture description hereInsert picture description here
Insert picture description here

Insert picture description hereInsert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Insert picture description here
Insert picture description hereInsert picture description here

classLoader is used to read .class files

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description hereInsert picture description here
Invoke shows that we use reflection here

Insert picture description hereInsert picture description here
The entry point is used to determine when to generate dynamic proxy objects.

Insert picture description here
Insert picture description hereInsert picture description here

Insert picture description here

Code implementation of aop

Insert picture description here
Insert picture description hereInsert picture description hereInsert picture description here

Insert picture description here

Insert picture description here
Insert picture description hereInsert picture description hereInsert picture description here
Cut into this implementation class

Insert picture description here

spring-aop (provides various notifications extended by spring (pre-notification, post-notification, surrounding notification, exception notification))

Insert picture description here

Insert picture description hereInsert picture description hereTransaction notification is a typical surround notification

Insert picture description hereThe surround notification does not belong to any layer of the project, so we need to create a new package called advices to save additional operations in our project.

Insert picture description here
Insert picture description hereInsert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here

Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
Insert picture description here
Insert picture description hereInsert picture description here
Insert picture description here
If you send an exception, you can’t enter the post
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/liulang68/article/details/109143919