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)
Project management is the creation, use and destruction of components.
Entity components are generally not handed over to spring to manage
The 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.
If the object is not created to call the method, a null pointer will appear
We 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
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
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),)
A property can only complete the assignment of one attribute. The name is used to specify which attribute name in the component is assigned.
What 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.
We look at the error of the framework from the bottom up
The properties collection is unordered
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))
The interface has the function of shielding the underlying implementation
classLoader is used to read .class files
Invoke shows that we use reflection here
The entry point is used to determine when to generate dynamic proxy objects.
Code implementation of aop
Cut into this implementation class
spring-aop (provides various notifications extended by spring (pre-notification, post-notification, surrounding notification, exception notification))
Transaction notification is a typical surround notification
The 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.
If you send an exception, you can’t enter the post