Spring Framework Architecture

Spring packaging is modular, allowing you to pick and choose the modules that are applicable to you, without any need to bring in the rest. The following section gives you a detailed explanation about different modules available in the Spring Framework. The following figure shows you a complete overview of the framework and modules supported by the Spring Framework:

Spring Framework Architecture

Spring Core Container

Spring Core Container consists of the core, beans, context, and expression language modules, as shown in the preceding figure. Let's discuss these in detail as follows:

  • Core module: This module of Spring Core Container is the most important component of the Spring Framework. It provides features such as IoC and Dependency Injection. The idea behind IoC is similar to the Hollywood principle: "Don't call me, I'll call you." Dependency Injection is the basic design principle in Spring Core Container that removes explicit dependence on container APIs.
  • Beans module: The bean module in Spring Core Container provides BeanFactory, which is a generic factory pattern that separates the dependencies such as initialization, creation, and access of the objects from your actual program logic. BeanFactory in Spring Core Container supports the following two scopes modes of object:
    • Singleton: In singleton, only one shared instance of the object with a particular name will be retrieved on lookup. Spring singleton returns a same bean instance per Spring IoC container. Each time you call getBean() on ApplicationContext, Spring singleton returns the same bean instance.
    • Prototype or non-singleton: In prototype, each retrieval results in the creation of a brand new instance. Each time you call getBean() on ApplicationContext, Spring prototype creates a separate bean instance.
  • Context module: An ApplicationContext container loads Spring bean definitions and wires them together. The ApplicationContext container is the focal point of the Context module. Hierarchical context is also one of the focal points of this API. ApplicationContext supports the Message lookup, supporting internationalization (i18N) messages.
  • Expression language: Spring Expression Language (SpEL) is a powerful expression language supporting the features for querying and manipulating an object graph at runtime. SpEL can be used to inject bean or bean property in another bean. SpEL supports method invocation and retrieval of objects by name from IoC container in Spring.

The AOP module

Spring's Aspect-oriented Programming (AOP) module is one of the main paradigms that provide an AOP implementation. Spring AOP module is a proxy-based framework implemented in Java. The Spring Framework uses AOP for providing most of the infrastructure logic in it.

AOP is a mechanism that allows us to introduce new functionalities into an existing code without modifying it design. AOP is used to weave cross-cutting aspects into the code. The Spring Framework uses AOP to provide various enterprise services, such as security in an application. The Spring AOP framework is configured at runtime.

Spring integrates with AspectJ, which is an extension of AOP. AspectJ lets programmers define special constructs called Aspects, which contains several entities unavailable to standard classes.

Data access/integration

Spring's data access addresses common difficulties developers face while working with databases in applications.

  • JDBC module: The Spring Framework provides solution for various problems identified using JDBC as low-level data access. The JDBC abstraction framework provided under the Spring Framework removes the need to do tedious JDBC-related coding. The central class of Spring JDBC abstraction framework is the JdbcTemplate class that includes the most common logic in using the JDBC API to access data such as handling the creation of connection, statement creation, statement execution, and release of resource. The JdbcTemplate class resides inside the org.springframework.jdbc.core package.
  • ORM module: The Object-relational mapping (ORM) module of the Spring Framework provides a high-level abstraction for ORM APIs, including JPA and Hibernate. Spring ORM module reduces the complexity by avoiding the boilerplate code from application.
  • OXM module: Spring OXM module stands for Spring Object XML Mappers, which supports Object/XML mapping. It also supports integration with Castor, JAXB, XmlBeans, and the XStream framework.

    Most applications need to integrate or provide services to other applications. One common requirement is to exchange data with other systems, either on a regular basis or in real time. In terms of the data format, XML is the most commonly used format. As a result, there exists a common need to transform a JavaBean into XML format and vice versa.

    Spring supports many common Java-to-XML mapping frameworks and, as usual, eliminates the need for directly coupling to any specific implementation. Spring provides common interfaces for marshalling (transforming JavaBeans into XML) and unmarshalling (transforming XML into Java objects) for DI into any Spring beans. Spring also has modules to convert data to and from JSON, in addition to OXM.

  • JMS module: The Java Messaging Service (JMS) module comprises features to produce and consume messages. It is a Java Message Oriented Middleware (MOM) API for sending messages between two or more clients. JMS is a specification that describes a common way for Java program to create, send, and read distributed enterprise messages.
    • Spring Java mail: The org.springframework.mail package is the root package that provides mail support in the Spring Framework. It handles electronic mail.
  • Transaction module: The Spring transaction module provides abstraction mechanism to supports programmatic and declarative transaction management for classes.

The Web module

The Web module consists of the Web, Servlet, Struts, and Portlet modules.

  • Web module: The Spring Web module builds on the application context module and includes all the support for developing robust and maintainable web application in a simplified approach. It also supports multipart file-upload functionality.
  • Servlet module: In Spring, the Servlet module contains Model-View-Controller (MVC) implementation that helps to build enterprise web applications. In Spring Framework, the MVC provides clean separation between binding request parameter, business objects, and controller logic.
  • Struts module: The Web Struts module supports integration of Struts Web tier within a Spring application. It also supports configuration of Struts Actions using Spring Dependency Injection.
  • Portlet module: Spring Portlet supports for easier development of web application using Spring. Portlet is managed by the Portlet container, similar to the web container. Portlet is used in the UI layer for displaying contents from data source for end user.

The Test module

In the Spring Framework, the Test module helps to test applications developed using the Spring Framework, either using JUnit or TestNG. It also helps in creating mock object to perform unit testing in isolation. It supports running integration tests outside the application server. We'll look at Spring's Test module in Chapter 6, Spring Testing.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.217.190.58