In 2002, the Aus­tralian developer Rod Johnson presented the code of the Java framework Interface21, which he had written specif­i­cal­ly for his own projects, in his work “Expert One-on-One J2EE Design and De­vel­op­ment”. On the basis of this code, he later developed the Spring framework, together with other pro­gram­mers, which was released for the first time under the free Apache 2.0 license on Source­Forge in June 2003. It’s still one of the most popular solutions for the de­vel­op­ment of en­ter­prise ap­pli­ca­tions in Java. The open source framework has since cleared up the weak points and limits of the standard de­vel­op­ment en­vi­ron­ment J2EE (now also known as the “Java platform”) as well as the component model En­ter­prise JavaBeans (EJB) by sig­nif­i­cant­ly reducing their com­plex­i­ty.

What is Spring?

Spring sim­pli­fies the de­vel­op­ment of Java ap­pli­ca­tions – re­gard­less of whether they are offline or web ap­pli­ca­tions. The biggest ad­van­tages of this framework are its lean source code and the minimal effort required for ad­just­ments. These comforts are provided to the pro­gram­mer based on the following prin­ci­ples, which are explained in Rod Johnson’s book:

  • De­pen­den­cy Injection (DI): De­pen­den­cy Injection refers to the external instance in object-oriented pro­gram­ming, which controls the de­pen­den­cies 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 pre­con­fig­ured classes, including their de­pen­den­cies, to the Java project.
  • Aspect-oriented pro­gram­ming: To increase the mod­u­lar­i­ty of object-oriented ap­pli­ca­tions even more, Spring also offers optional aspect-oriented pro­gram­ming ap­proach­es which use the AspectJ language. This allows aspects, or cross-component con­nec­tions, which are in­evitable in complex systems, to be struc­tured syn­tac­ti­cal­ly. This has the advantage that the actual program code can be separated from technical processes such as error handling, val­i­da­tion, or security.
  • Templates: Templates in Spring are denoted as classes for various program in­ter­faces, and simply the work with APIs by providing automatic resource man­age­ment, uniform error handling, and other help.

By following the prin­ci­ples outlined above, the Spring framework allows de­vel­op­ers to access Plain Old Java Objects, or POJOs (or common Java objects) when de­vel­op­ing En­ter­prise Java ap­pli­ca­tions. As opposed to the En­ter­prise JavaBeans (EJBs), POJOs don’t need a specific ap­pli­ca­tion server that supports the EJB con­tain­ers – standard solutions such as Tomcat are com­plete­ly suf­fi­cient. To use Spring, you also need the Java SE De­vel­op­ment Kit (SDK).

Spring: In­tro­duc­tion to the most important module

For many ap­pli­ca­tions in Java, Spring is the perfect choice – mainly due to the modular structure of the framework. Around 20 modules are available for de­vel­op­ment with Spring. You can freely choose which com­po­nents you need for your ap­pli­ca­tion and which you don’t. In the standard con­struc­tion, the different modules are separated into the following six cat­e­gories:

  • Core container: The core container includes the el­e­men­tary modules spring-core, spring-beans, spring-context, spring-context-support, and spring-ex­pres­sion. Core and Beans build the basic outline of the framework and contain, for example, the de­pen­den­cy injection function as well the POJO support. The context module inherits its features from the Beans module and adds functions to the ap­pli­ca­tion, for example, for in­ter­na­tion­al­iza­tion or loading of resources. In addition, Java En­ter­prise features like EJB and JMX (Java Man­age­ment Ex­ten­sions) are supported. With the help of context-support, libraries from third parties can be joined with Spring. Spring-ex­pres­sion contains the Spring Ex­pres­sion Language (SPeL), a de­vel­op­ment of the Unified Ex­pres­sion Language of the JSP 2.1 spec­i­fi­ca­tion (JavaServ­er Pages).
  • AOP and in­stru­men­ta­tion: To enable aspect-oriented pro­gram­ming, the Spring framework contains the module spring-AOP as well as the module spring-aspects for the in­te­gra­tion of the pre­vi­ous­ly mentioned language AspectJ. The spring-in­stru­ment component allows you to in­stru­men­tal­ize Java classes – that is, to change bytecode at runtime – and also adds Class­Loader im­ple­men­ta­tions for different ap­pli­ca­tion servers.
  • Messaging: To function as the foun­da­tion for message-based ap­pli­ca­tions, Spring has some key features of the key Spring In­te­gra­tion project – such as, for example, “Message”, “Mes­sageChan­nel”, or “Mes­sage­Han­dler”. The cor­re­spond­ing module is named spring-messaging.
  • Data access/in­te­gra­tion: The modules in this category are designed to give Java ap­pli­ca­tions the ability to interact with other ap­pli­ca­tions and manage data access. The module spring-JDBC, for example, provides an ab­strac­tion layer that defines how a client accesses the database and elim­i­nates the need for a cum­ber­some JDBC coding. Spring-ORM, on the other hand, provides in­te­gra­tion layers for popular ORM in­ter­faces that allow access to re­la­tion­al databases. The other com­po­nents are spring-TX (supports program trans­ac­tion man­age­ment for all classes and POJOs), spring-OXM (ab­strac­tion layers for object/XML mapping), and spring-JMS, a module with features for the pro­duc­tion and handling of messages.
  • Web: In this category, you’ll find the web ap­pli­ca­tion-specific modules spring-web, spring-webmvc, and spring-websocket. The first adds the typical web-oriented in­te­gra­tion features to the Java ap­pli­ca­tion, 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 im­ple­men­ta­tions for the re­al­iza­tion of the standard model view con­troller ar­chi­tec­ture and the REST web services. Spring-websocket enables data transfer between client and server on the basis of Web­Sock­ets.
  • Test: The spring-test module makes it possible to check the func­tion­al­i­ty of the com­po­nents of your Java ap­pli­ca­tion. With the cor­re­spond­ing sup­ple­men­tary frame­works, such as Junit or TestNG, you can perform extensive unit tests (with the focus on a single component) as well as in­te­gra­tion tests (with the focus on the interplay of several com­po­nents).

Spring: Java in modern web de­vel­op­ment

From the beginning, Java, including the tech­nolo­gies related to it, was designed for use in web de­vel­op­ment. After start-up dif­fi­cul­ties due to the low support levels of earlier browsers, the then very low bandwidth of private internet con­nec­tions, not-to-mention the limited computing power of PCs at the time, the pro­gram­ming language finally ex­pe­ri­enced its break­through at the end of the 1990s. At the beginning stages of the World Wide Web Java applets were popular – these are ap­pli­ca­tions written in Java that can be run using ap­pro­pri­ate runtime en­vi­ron­ments in the browser and can interact with the user without having to send data to the server. Due to their resource de­pen­den­cy they weren’t very practical. With the in­tro­duc­tion of mobile devices that don’t support browser applets, the in­ter­ac­tive web elements have com­plete­ly dis­ap­peared from the scene.

While Java flopped rel­a­tive­ly quickly in the frontend, the pro­gram­ming language has become a staple on the server side where the ap­pli­ca­tion scenarios vary quite a lot: From servlets for server-run applet coun­ter­parts to complex en­ter­prise solutions like mid­dle­ware, banking software, or large content man­age­ment systems, a wide variety of Java tech­nolo­gies are more in demand than ever, budget allowing. Because of its ad­van­tages in terms of cost and time, the PHP scripts language is used on about three-quarters of all websites. For web de­vel­op­ers who work with Java, Spring offers not only the required struc­tures but also a con­sid­er­able sim­pli­fi­ca­tion of the work process. The ad­van­tages of Java web de­vel­op­ment include, but aren’t limited to, platform in­de­pen­dence, the ability to integrate with en­ter­prise software and processes, and a clear structure.

Which projects are best suited to the Spring framework?

Spring is typically used as a light­weight framework for Java ap­pli­ca­tions since almost no ad­just­ments to the source code are necessary to profit from its many ad­van­tages. Among other things, there are sim­pli­fi­ca­tions of the im­ple­men­ta­tion of trans­ac­tion man­age­ment, in­ter­faces, and database access. The ability to carry out un­com­pli­cat­ed unit and in­te­gra­tions tests is also a key reason for the pop­u­lar­i­ty of the Spring framework. But the central point is without a doubt the aban­don­ment of platform-specific and non-stan­dard­ized com­po­nents, which makes Spring both highly portable and in­de­pen­dent of ap­pli­ca­tion servers. For this reason, you can easily employ a meta-framework in which further external com­po­nents or entire frame­works will be in­te­grat­ed. A typical ap­pli­ca­tion example is the de­vel­op­ment of backends on the basis of Spring, which is then linked to a frontend pre­vi­ous­ly created using a UI framework such as Twitter Bootstrap. Spring is par­tic­u­lar­ly strong in the re­al­iza­tion of complex business ap­pli­ca­tions. For companies, the Spring framework in addition to Java has been an excellent choice for years for im­ple­ment­ing the required tech­nolo­gies. Unlike pure web frame­works – such as Strate’s Apache com­peti­tor project – Spring is not limited to web ap­pli­ca­tions, but also enables the de­vel­op­ment of native desktop solutions. For simple ap­pli­ca­tions – whether online or offline – Spring (and Java) are less suitable, even if the im­ple­men­ta­tion of such projects is possible in principle.

The benefits of Spring: an overview

If you are preparing for the de­vel­op­ment of your next big project and are on the search for a suitable framework, you should consider using the Spring framework. Es­pe­cial­ly if Java plays a role in your plans, then you can con­sid­er­ably simplify your work by using its flexible module col­lec­tion. This gives you a powerful basic structure that you hardly ever need to change and instead can focus your efforts entirely on de­vel­op­ing the actual business logic. In the official GitHub repos­i­to­ry you can download and try out the framework at any time. Here are the ad­van­tages of the Java de­vel­op­ment en­vi­ron­ment once again, listed for you clearly:

  • POJOs can be applied for extra logic
  • Finished basic framework that hardly needs to be modified
  • No ap­pli­ca­tion server required
  • Enables unit and in­te­gra­tion tests
  • MVC ar­chi­tec­ture
  • Aspect-oriented pro­gram­ming with AspectJ is possible
  • De­pen­den­cy injection (external de­pen­den­cy control)
  • Pro­gram­mat­ic trans­ac­tion man­age­ment
Go to Main Menu