Spring Framework Introduction---The main source of this article: Http://www.cnblogs.com/jingmoxukong/p/4506493.html
Spring's current framework has a jar package that can be roughly divided into 6 main modules:
- Core Container
- AOP and Instrumentation
- Messaging
- Data access/integration
- Web
- Test
The spring framework provides a very rich feature, so the entire architecture is huge.
in our actual application development, it is not necessary to use all the functions, but to select the appropriate spring modules as needed.
2.1.1 Spring key Strategy
Before introducing the six modules, it is important to first explain spring's two key strategies, which are the cornerstone of the spring framework.
(1) controlled inversion (inversion of control), English abbreviation IOCapplying control inversion, when an object is created, it is passed to it by an external entity that controls all objects in the system by a reference to its dependent object.
It can also be said that the dependency is injected into the object. So, control reversal is a reversal of this responsibility about how an object obtains a reference to the object he relies on.
There are two main aspects of control inversion:
- Dependency Injection (Dependency injection), abbreviated as DI
- Dependency lookup (Dependency lookup)
Among them, the application of dependency injection is more extensive.
Dependency Injection is a technique that means that a component does not make a location query, but only provides a common Java method for the container to determine the dependency relationship.
The Assembly of the container's full-fledged component, which passes the object that conforms to the dependency to the desired object through the JavaBean property or constructor function.
The practice of injecting dependencies through the JavaBean attribute is called SetPoint method Injection (setterinjection); the practice of passing dependencies as constructor arguments is called constructor injection (constructorinjection) .
(2) Plane-oriented programming (Aspect oriented Programming), abbreviated to AOP
a technology that implements the unified maintenance of program functions by means of precompilation and runtime dynamic agent.
AOP enables the isolation of parts of the business logic, which reduces the coupling between parts of the business logic, improves the reusability of the program, and improves the efficiency of development.
2.1.2 Core container (Corecontainer)
The IOC container is the core of the spring framework. The spring container uses Dependency Injection Management to form the component of the application, which creates an association between the components that work together. Without a doubt, these objects are simpler, cleaner, easier to understand, and easier to reuse and test.
Spring comes with implementations of several containers, which can be summed up in two categories:
(1) Bean Factory
Defined by the org.springframework.beans.factory.BeanFactory interface.
It is the simplest container that provides basic DI support.
(2) Application context
Defined by the org.springframework.context.ApplicationContext interface.
It is built on top of Beanfactory and provides application-oriented services, such as the ability to parse textual information from a property file, and the ability to publish application events to listeners of interest.
Note: The Bean factory is often too low-level for most applications, so the application context is more widely used. It is recommended to use the application context container in development.
Spring comes with a variety of application contexts, most likely to be encountered in the following ways:
- classpathxmlapplicationcontext--load the context definition from the XML configuration file under the Classpath and use the context definition file as a class resource.
- Filesystemxmlapplicationcontext-Reads the XML configuration file under the file system and loads the context definition.
- Xmlwebapplicationcontext-Reads the XML configuration file under the Web application and loads the context definition.
The following is an example of loading an app context
ApplicationContext context = new filesystemxmlapplicationcontext ("D:\\temp\\build.xml");
ApplicationContext context2 = new classpathxmlapplicationcontext ("Build.xml");
As you can see, loading filesystemxmlapplicationcontext and Classpathxmlapplicationcontext are very similar.
The difference is that the former locates the build.xml file under the specified file system path, and then finds the Build.xml file under all classpath (including jar files).
by referencing the application context, it is convenient to call the Getbean () method to get the Bean from the Spring container.
Related jar Packages
spring-core,
Spring-beans, provides a fundamental part of the framework, including IOC and dependency injection characteristics.
Spring-context, built on the basis of Spring-core, Spring-beans. It provides a way to access the object in a frame style.
It also supports Java EE-like features such as EJB,JMX and basic remoting. The ApplicationContext interface is its focal point.
Springcontext-support, integrating third-party libraries into spring application context.
Spring-expressionprovides a powerful expression language at runtime to query and manipulate an object graph.
2.1.3 AOP and Instrumentation The associated jar package
SPRING-AOPprovides rich support for slicing-oriented programming.
spring-aspectsprovides the integration of the ASPECTJ.
spring-instrument, provides support for class instrumentation and class loaders.
spring-instrument-tomcat, which contains spring's instrumentation proxy for Tomcat.
2.1.4 Messaging The associated jar package ,
spring-messaging, contains the message processing features of spring, such as Message,messagechannel,messagehandler.
2.1.5 Data access and Integration (dataaccess/integaration)the Data access/integration layer contains the JDBC/ORM/OXM/JMS and transaction modules. The associated jar package ,
spring-jdbc, provides a JDBC abstraction layer.
Spring-tx, supports programmatic and declarative transaction management classes.
Spring-orm, provides a collection of popular object-relational mapping APIs, such as Jpa,jdo,hibernate.
SPRING-OXMprovides an abstraction layer to support the implementation of object/xml mappings, such as JAXB,CASTOR,XMLBEANS,JIBX and XStream.
SPRING-JMS, which includes the ability to produce and consume messages.
2.1.6 Web Related jar Packages
spring-webprovides basic web-oriented features, such as multi-file uploads, and the initialization of an IOC container using a servlet listener. A web-oriented application layer context.
Spring-webmvc, including MVC and Rest Web service implementations.
Spring-webmvc-portlet, provides an image of the MVC implementation and SPRING-WEBMVC functionality in the Protlet environment.
2.1.7 Testing (test) related jar package
spring-test, with JUnit and testng to support unit testing and integration testing of spring components.
Spring Framework Introduction