In the previous article gave a simple application of spring, the following system to say my understanding of spring, if there is wrong or imperfect place, I hope you can correct, welcome everyone to discuss together.
Spring provides a lightweight solution for creating enterprise-class applications. Spring contains too much content, but you can only use the parts you need, because spring is modular. Spring can also be well integrated with the current mainstream framework, such as the Struts2 of request forwarding, persistent hibernate, Mybatis, JTA, and so on.
Referring to spring, we have to say that IOC (control inversion, DI: Dependency injection) and AOP (aspect-oriented programming). In the end how to understand these two things, this is not overnight can understand the particularly thorough, need to accumulate in the process, gradually deepen the understanding of this thing, I briefly say my understanding.
IoC (Inversion of control): controlled inversion, is the use of thought, not technology. Who controls who, what controls? What has been reversed? IOC creates objects and controls them so that dependent objects are retrieved in a reversed way! for what? Because we know that a complex system has a lot of classes, and these classes work together, and it's more straightforward to say that your class needs to invoke the methods provided by other classes, and this time we usually get a different class object through new, which is what the programmer does , a more powerful programmer might use Factory mode or other design patterns to encapsulate the process of acquiring objects, while the process of acquiring objects in general is managed by the programmer himself. After we used spring, we no longer had to manage how to create dependent objects, which was given to the IOC container, and we simply registered the beans we relied on in the IOC container, and when we needed to, we obtained the dependent objects through the methods provided by the IOC container. Compared to our traditional way of acquiring objects, it is not control inversion, the programmer manages itself, and becomes managed by spring's IOC container. The best thing about it is decoupling.
Often with the IOC there is a DI (Dependency injection): Dependency Injection. Di was presented by Martin Fowler, which was in 2004, in explanation of "what does the IOC's control reverse?" "At the time, give a new name. is actually a more straightforward name for the IOC control reversal: Because we are using Spring's IOC container, the creation of the beans that are dependent on the objects is given to the IOC container, and in the process of running the system we need to get the beans we rely on to the IOC container, this time, The IOC container injects the beans we need into our class, where the application relies on the IOC container and requires the IOC container to inject the external resources (that is, the objects, data, files, etc.) that the application relies on to the application. This concept is much easier to understand than the IOC control reversal. Above is my understanding of the IOC and DI, and if there is something wrong or unclear, please discuss it.
Here's a simple example to illustrate that there is a reference to a in two classes A and b,b, B depends on a:
Class A{}class b{private a A; public void SetA (a a) {THIS.A = A; }}
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/24/wKioL1VAz3GyyqApAACmWHglOos229.jpg "title=" Traditional way Vsioc Way "alt=" Wkiol1vaz3gyyqapaacmwhgloos229.jpg "/>
The traditional way we need to create the object ourselves, and then through the set method, injected into, after the IOC container, we only need a simple sentence: b b = Getb (); The IOC container will automatically inject a B object dependent on a.
AOP (aspect-oriented programming): Plane-oriented programming. AOP is actually the complement and consummation of object-oriented programming (Oop:object oriented programing) thought. We know that OOP introduces the concepts of "abstraction", "encapsulation", "Inheritance", "polymorphism", and the abstraction and encapsulation of everything to create a hierarchy of objects, which emphasizes the top-down relationship of a whole thing. But the specific granularity to the internal situation of each thing, oop seems powerless. such as the log function. Log code tends to spread horizontally across all object hierarchies, but it has nothing to do with the core functionality of the objects it spreads to. This is true for many other similar functions, such as transaction management, permission control, and so on. This leads to a large amount of duplication of code, which is not conducive to the reuse of individual modules. PS: In fact, I have a certain understanding of AOP, but can not be particularly clear to express it .....
Take a look at an overview of the spring framework given in the official Spring Reference document:
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/6C/1B/wKiom1U_nyaw2L1NAAHqakQIOdc078.jpg "title=" Official document-spring overview diagram. png "alt=" wkiom1u_nyaw2l1naahqakqiodc078.jpg "/>
Spring's core container consists of the following modules: Spring-core,spring-beans,spring-context,spring-context-support, and spring-expression (Spring expression Language).
The Core (Spring-core) module and the Beans (Spring-beans) module are the basic parts of the spring framework, enabling IOC containers and dependency injection. The beanfactory is a typical factory pattern implementation that allows you to decouple the actual dependencies through the configuration file, without having to consider writing a single piece.
The Context (spring-context) module, which is based on the core and beans modules, provides the Spring Framework Access object method, which is similar in principle to the Jndi registry. The context module inherits the features of the beans module and also adds internationalization support, event propagation, resource loading, and transparency to create an application context, such as creating a servlet container. The context module also supports some features of Java EE, such as EJB, JMX, and basic remote operations. The ApplicationContext interface is the focus of the context module. Spring-context-support provides support for consolidating third-party libraries into the spring application context, including: Caching (Ehcache,guava,jcache), mailing (JavaMail), scheduling framework (COMMONJ, Quartz) as well as the template engine (freemarker,jasperreports,velocity).
The Spel (spring-expression) module provides a powerful expression language that can query and manipulate objects at run-time. Spel is an extension of the El expression. Supports setting and getting property values, property assignments, method invocations, access to arrays, collections, content in indexers, logical operations and arithmetic, variable naming, retrieving objects from spring's IOC container.
It also supports list projection and selection, as well as common list aggregation.
The AOP module provides support for aspect-oriented programming, which allows spring to seamlessly interface with ASPECTJ due to the presence of spring-aspects.
Data access/integration has JDBC, ORM, OXM, JMS, and transactional components. SPRING-JDBC provides an abstraction of JDBC, omitting the lengthy JDBC code. The SPRING-TX module provides support for declarative transactions. Spring-orm provides integrated support for other ORM frameworks, such as JPA, JDO, Hibernate.
The Web tier includes Spring-web, SPRING-WEBMVC, Spring-websocket, and Spring-webmvc-portlet. The Spring-web module provides basic Web integration features, such as file uploads, to initialize the IOC container through the servlet listener and the web context. SPRING-WEBMVC includes spring's MVC, which supports restful web Service.
The above paragraph is basically a reference to the official Spring document translation, if not, or the translation of inappropriate places, welcome criticism, hope to be able to communicate with you more.
This article is from "Ace's Dream" blog, please be sure to keep this source http://acesdream.blog.51cto.com/10029622/1640459
Spring Learning Series--chapter II: Spring Overview