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 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:
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:getBean()
on ApplicationContext
, Spring singleton returns the same bean instance.getBean()
on ApplicationContext
, Spring prototype creates a separate bean instance.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.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.
Spring's data access addresses common difficulties developers face while working with databases in applications.
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.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.
org.springframework.mail
package is the root package that provides mail support in the Spring Framework. It handles electronic mail.The Web module consists of the Web, Servlet, Struts, and Portlet modules.
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.