Spring – Framework for Java applications

In 2002, the Australian developer Rod Johnson presented the code of the Java framework Interface21, which he had written specifically for his own projects, in his work “Expert One-on-One J2EE Design and Development”. On the basis of this code, he later developed the Spring framework, together with other programmers, which was released for the first time under the free Apache 2.0 license on SourceForge in June 2003. It’s still one of the most popular solutions for the development of enterprise applications in Java. The open source framework has since cleared up the weak points and limits of the standard development environment J2EE (now also known as the “Java platform”) as well as the component model Enterprise JavaBeans (EJB) by significantly reducing their complexity.

What is Spring?

Spring simplifies the development of Java applications – regardless of whether they are offline or web applications. The biggest advantages of this framework are its lean source code and the minimal effort required for adjustments. These comforts are provided to the programmer based on the following principles, which are explained in Rod Johnson’s book:

  • Dependency Injection (DI): Dependency Injection refers to the external instance in object-oriented programming, which controls the dependencies of the objects. Spring uses the Java component JavaBeans for this. They function in Java as a container for data transfer, which is why they serve as a template for all managed resources (“beans”) in the Spring framework. In this way, Spring can act as a container that provides preconfigured classes, including their dependencies, to the Java project.
  • Aspect-oriented programming: To increase the modularity of object-oriented applications even more, Spring also offers optional aspect-oriented programming approaches which use the AspectJ language. This allows aspects, or cross-component connections, which are inevitable in complex systems, to be structured syntactically. This has the advantage that the actual program code can be separated from technical processes such as error handling, validation, or security.
  • Templates: Templates in Spring are denoted as classes for various program interfaces, and simply the work with APIs by providing automatic resource management, uniform error handling, and other help.

By following the principles outlined above, the Spring framework allows developers to access Plain Old Java Objects, or POJOs (or common Java objects) when developing Enterprise Java applications. As opposed to the Enterprise JavaBeans (EJBs), POJOs don’t need a specific application server that supports the EJB containers – standard solutions such as Tomcat are completely sufficient. To use Spring, you also need the Java SE Development Kit (SDK).

Spring: Introduction to the most important module

For many applications in Java, Spring is the perfect choice – mainly due to the modular structure of the framework. Around 20 modules are available for development with Spring. You can freely choose which components you need for your application and which you don’t. In the standard construction, the different modules are separated into the following six categories:

  • Core container: The core container includes the elementary modules spring-core, spring-beans, spring-context, spring-context-support, and spring-expression. Core and Beans build the basic outline of the framework and contain, for example, the dependency injection function as well the POJO support. The context module inherits its features from the Beans module and adds functions to the application, for example, for internationalization or loading of resources. In addition, Java Enterprise features like EJB and JMX (Java Management Extensions) are supported. With the help of context-support, libraries from third parties can be joined with Spring. Spring-expression contains the Spring Expression Language (SPeL), a development of the Unified Expression Language of the JSP 2.1 specification (JavaServer Pages).
  • AOP and instrumentation: To enable aspect-oriented programming, the Spring framework contains the module spring-AOP as well as the module spring-aspects for the integration of the previously mentioned language AspectJ. The spring-instrument component allows you to instrumentalize Java classes – that is, to change bytecode at runtime – and also adds ClassLoader implementations for different application servers.
  • Messaging: To function as the foundation for message-based applications, Spring has some key features of the key Spring Integration project – such as, for example, “Message”, “MessageChannel”, or “MessageHandler”. The corresponding module is named spring-messaging.
  • Data access/integration: The modules in this category are designed to give Java applications the ability to interact with other applications and manage data access. The module spring-JDBC, for example, provides an abstraction layer that defines how a client accesses the database and eliminates the need for a cumbersome JDBC coding. Spring-ORM, on the other hand, provides integration layers for popular ORM interfaces that allow access to relational databases. The other components are spring-TX (supports program transaction management for all classes and POJOs), spring-OXM (abstraction layers for object/XML mapping), and spring-JMS, a module with features for the production and handling of messages.
  • Web: In this category, you’ll find the web application-specific modules spring-web, spring-webmvc, and spring-websocket. The first adds the typical web-oriented integration features to the Java application, such as an upload function for multipart data or an HTTP client. The spring-webmvc module is also referred to as a web servlet and contains the Spring implementations for the realization of the standard model view controller architecture and the REST web services. Spring-websocket enables data transfer between client and server on the basis of WebSockets.
  • Test: The spring-test module makes it possible to check the functionality of the components of your Java application. With the corresponding supplementary frameworks, such as Junit or TestNG, you can perform extensive unit tests (with the focus on a single component) as well as integration tests (with the focus on the interplay of several components).

Spring: Java in modern web development

From the beginning, Java, including the technologies related to it, was designed for use in web development. After start-up difficulties due to the low support levels of earlier browsers, the then very low bandwidth of private internet connections, not-to-mention the limited computing power of PCs at the time, the programming language finally experienced its breakthrough at the end of the 1990s. At the beginning stages of the World Wide Web Java applets were popular – these are applications written in Java that can be run using appropriate runtime environments in the browser and can interact with the user without having to send data to the server. Due to their resource dependency they weren’t very practical. With the introduction of mobile devices that don’t support browser applets, the interactive web elements have completely disappeared from the scene.

While Java flopped relatively quickly in the frontend, the programming language has become a staple on the server side where the application scenarios vary quite a lot: From servlets for server-run applet counterparts to complex enterprise solutions like middleware, banking software, or large content management systems, a wide variety of Java technologies are more in demand than ever, budget allowing. Because of its advantages in terms of cost and time, the PHP scripts language is used on about three-quarters of all websites. For web developers who work with Java, Spring offers not only the required structures but also a considerable simplification of the work process. The advantages of Java web development include, but aren’t limited to, platform independence, the ability to integrate with enterprise software and processes, and a clear structure.

Which projects are best suited to the Spring framework?

Spring is typically used as a lightweight framework for Java applications since almost no adjustments to the source code are necessary to profit from its many advantages. Among other things, there are simplifications of the implementation of transaction management, interfaces, and database access. The ability to carry out uncomplicated unit and integrations tests is also a key reason for the popularity of the Spring framework. But the central point is without a doubt the abandonment of platform-specific and non-standardized components, which makes Spring both highly portable and independent of application servers. For this reason, you can easily employ a meta-framework in which further external components or entire frameworks will be integrated. A typical application example is the development of backends on the basis of Spring, which is then linked to a frontend previously created using a UI framework such as Twitter Bootstrap. Spring is particularly strong in the realization of complex business applications. For companies, the Spring framework in addition to Java has been an excellent choice for years for implementing the required technologies. Unlike pure web frameworks – such as Strate’s Apache competitor project – Spring is not limited to web applications, but also enables the development of native desktop solutions. For simple applications – whether online or offline – Spring (and Java) are less suitable, even if the implementation of such projects is possible in principle.

The benefits of Spring: an overview

If you are preparing for the development of your next big project and are on the search for a suitable framework, you should consider using the Spring framework. Especially if Java plays a role in your plans, then you can considerably simplify your work by using its flexible module collection. This gives you a powerful basic structure that you hardly ever need to change and instead can focus your efforts entirely on developing the actual business logic. In the official GitHub repository you can download and try out the framework at any time. Here are the advantages of the Java development environment once again, listed for you clearly:

  • POJOs can be applied for extra logic
  • Finished basic framework that hardly needs to be modified
  • No application server required
  • Enables unit and integration tests
  • MVC architecture
  • Aspect-oriented programming with AspectJ is possible
  • Dependency injection (external dependency control)
  • Programmatic transaction management
Was this article helpful?
We use cookies on our website to provide you with the best possible user experience. By continuing to use our website or services, you agree to their use. More Information.
Page top