Spring Framework Overview

Spring framework is a lightweight solution and a potential one-stop platform for building enterprise applications. Spring is modular, which allows you to use only those modules that you need without introducing unnecessary modules.

You can use the IoC container and use any Web framework on it (for example Struts, Hibernate, and even JDBC abstraction layer). It also supports declarative transaction management, remote access to your logic through RMI or web services, and options for supporting various data persistence. It provides a full-featured MVC framework and enables you to transparently integrate AOP into your software.

Spring is designed to be non-invasive, meaning that your business logic code is usually not dependent on the framework itself. At your integration layer (for example, the data access layer), there will be some dependencies on data access techniques and Spring library files. However, in the rest of your code library, these dependencies are easily isolated.

1. Spring Framework Introduction.

Spring framework provides a wide range of infrastructure to support the development of Java applications. It controls the infrastructure itself so that you can focus on your application. Spring enables you to build applications with simple Java objects (POJOs). And you can apply enterprise services to POJO in a non-intrusive way. This function applies to the Java SE programming model, all and part of the Java EE also.

Spring platform has below advantages.

  1. Execute the database transaction using the Java method without having to refer to transaction API.
  2. Use the local Java method to execute the remote procedure without involving remote API.
  3. Perform administrative actions using the local Java method without having to refer to JMX API.
  4. Use the local Java method for message handling without having to refer to JMS API.

1.1 Dependency Injection And Control Inversion.

Java application is a broad term, includes N tier server-side enterprise applications from restricted applets, the entire application is usually made up of multiple objects by collaboration. As a result, objects in an application depend on each other.

Although the Java platform offers rich application development capabilities, it lacks the means to organize its basic building blocks into an organic whole, throwing these tasks only to architects and developers. The Spring Framework’s Inverse Of Control (IoC) component provides a solution to this problem, which provides an effective method to assemble different components into a fully working application.

1.2 Spring Modules.

The functions contained in the Spring framework are organized into about 20 modules. These modules are divided into Core Container, Web, Data Access/Integration,  AOP (Aspect Oriented Programming), Test, and Instrumentation.

1.2.1 Core Container.
  1. The core container contains the Core, Beans, Context, and SpEL( Spring Expression Language) modules.
  2. The Core and Bean modules provide the foundation for the framework, including the IoC and Dependency Injection capabilities.
  3. BeanFactorys is a factory model for precision implementation. It eliminates the need for Programming single instances and allows you to remove configuration information and coupling between specific dependencies of the actual program logic.
  4. The Context module builds on the top of Core and Bean modules, it allows you to access objects in the framework, which is similar to the registration of JNDI.
  5. The Context module inherits the features from the Bean module and adds support for internationalization (such as using resource packs), event propagation, resource loading, and the transparent creation of contexts (such as Servlet containers).
  6. The context module also supports Java EE features such as EJB, JMX, and basic remote invocation. The ApplicationContext interface is the focus of the context module.
  7. The expression language module provides a powerful expression language for querying and manipulating object graphs at run time. This is an extension of the unified expression language (Unified, EL) in the JSP 2.1 specification.
  8. The expression language supports setting and getting property values, property definitions, method calls, access arrays, collections, and index contexts. Supports logical and numeric operations, naming variables, retrieving objects from the IoC container in Spring by name. It also supports selection operations of a list, as well as the common list aggregation operations.
1.2.2 Data Access And Integration.
  1. The data access/integration layer includes JDBC, ORM, OXM, JMS, and Transaction modules.
  2. JDBC module provides JDBC abstraction layers that do not need to write lengthy JDBC code and parse database vendor-specific error codes.
  3. The ORM module provides the integration layer for the popular object-relational mapping API, including JPA, JDO, and Hibernate.
  4. Using the ORM package, you can use all of the O/R mapping frameworks and combine all of the other features provided by Spring, such as the simple declarative transaction management function mentioned earlier.
  5. The OXM module integrates the abstraction layers that support object/XML mapping implementations, including JAXB, Castor, XMLBeans, JIBX, and XStream.
  6. The Java messaging service (the JMS module) contains the features that generate and process messages.
  7. The Transaction module supports programmatic and declarative transaction management for classes that implement specific interfaces and all POJO (common Java objects).
1.2.3 Web Module.
  1. The Web layer contains the Web, Web-Servlet, WebSocket, and Web-Portlet modules.
  2. The Spring Web module provides the basic Web-oriented integration capabilities, such as multiple file uploads, initialization of IoC containers using the Servlet listener, and the Web application context.
  3. The Spring Web module also contains the web-related parts of the Spring remote access support.
  4. The Web-Servlet module contains the implementation of the Spring model view controller (MVC) for Web applications.
  5. The Spring MVC framework provides a clear separation between domain model code and Web forms and integrates all other features of the Spring framework.
1.2.4 AOP And Instrumentation Infrastructure Components.
  1. The Spring AOP module provides AOP alliance compliant aspect-oriented programming, which allows you to customize, for example, method interceptors, and cut-in points to completely separate code from each function.
  2. Using the metadata function at the source code level, you can also include behavior information in your code to some extent, similar to the .NET attribute.
  3. Individual Aspects modules provide integrated use of AspectJ. The Instrumentation module provides support for class instrumentation and class loader implementation for some application servers.
1.2.5 Test Module.
  1. The test module supports the use of JUnit or TestNG to test Spring components.
  2. It provides consistent loading of Spring ApplicationContexts and caching of these contexts.
  3. It also provides mock objects that you can use to test your code in isolation.

1.3 Application Scenarios.

  1. The modules described earlier make Spring an ideal choice in many scenarios, from small programs to enterprise applications can all use Spring’s transaction management capabilities and web framework integration.
  2. Spring declarative transaction management capabilities make web applications completely transactional as if you were using the EJB container to manage transactions.
  3. All custom business logic can be implemented in a simple POJO and managed using the Spring IoC container.
  4. Spring ORM supports the integration of JPA, Hibernate, and JDO. For example, when using Hibernate, you can continue using existing mapping files and standard Hibernate SessionFactory configurations.
  5. The form controller seamlessly integrates the Web layer and the domain model bean, eliminating the need for using ActionForms or other classes to pass the values of the HTTP arguments to the domain model bean.
  6. In some cases, you are not allowed to switch to a different framework that you are using. Spring does not force you to use it only, it is not a full or nothing solution.
  7. Existing front-end frameworks, such as Struts, Tapestry, JSF, or other UI frameworks that allow the use of Spring transaction capabilities, can be integrated with the Spring intermediate layer.
  8. You just need to use ApplicationContext to connect your business logic and integrate your web layer using WebApplicationContext.
  9. When you need to access existing code through web service, you can use Spring’s Hessian-, Burlap-, Rmi- or JaxRpcProxyFactory classes. Enabling remote access to existing applications is not difficult.
  10. Spring Framework provides enterprise Java Bean (EJB ) access and abstraction layer, it can reuse existing POJO and packaging them into a stateless session bean, applied to a scalable web application.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.