current position:Home>Understanding of spring

Understanding of spring

2022-01-26 22:54:53 #HashMap#

One .Spring What is it?

Spring It's a lightweight Java Development framework , Its core is IOC( Inversion of control ) and AOP( Section oriented programming ).

Then I will analyze it one by one “ Lightweight ”“ frame ”“IOC”“AOP” The meaning of .

Lightweight : about Spring It is lightweight in terms of size and overhead

frame :Spring Put many components such as Strus and Hibernate combined , Make the development greatly simplified

IOC: Manages the javabean Object configuration and lifecycle , Rely on annotations , Give control of creating objects to IOC Container management

AOP: Put some system services that have nothing to do with business logic ( journal , Business , authentication ) It was packaged , Significantly reduces duplication of code

Two .IOC Containers

IOC Container management javabean Object configuration and what cycle, and some annotations of dependency injection . No, IOC In the case of containers , Objects are created by our programmers , And get your own dependence , At this time, the control is in the hands of programmers . If you don't understand , for instance : Two objects A,B,A,B Interdependence , When we create A when , because A,B Interdependence , At this time, we have to create B. But with IOC Then we just need to create A,IOC The container will automatically A China needs B Dependency injection of . This is the embodiment “ Inversion of control ”.

3、 ... and .AOP

The system consists of many components , Each component has different functions , But sometimes each component needs to be used with each other , about OOP for , It can only define the relationship between up and down , You can't define the relationship between left and right . Maybe it's not easy to understand here , A simple example , There are two functional modules: order module and commodity module , For the log function , stay OOP Under the circumstances , It is distributed in each module , In other words, it is scattered in the order and commodity modules , In this case, there is a lot of duplicate code , So how to solve it ? And that's where it comes in AOP Thought , Encapsulate the log , As a cross section , So you can run through all modules .AOP Enhance the function of some or some object , And it greatly simplifies the code . The following diagram is helpful to understand and compare

 

copyright notice
author[#HashMap#],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201262254508399.html

Random recommended