spring

How to Download Spring Framework JARs

1. Introduction

This article will look at how to download and set up Spring Framework JARs on a Windows system.

2. What is Spring?

Spring is an application development framework for Java-Based Enterprise applications. With the Spring framework, we write reliable, high-performance, testable code for Java enterprise applications. Rod Johnson is the creator of Spring, and the first version came in June 2003.

2.1 Why do we need Spring when we have a JEE framework?

The primary reason for creating Spring was to make Java EE application building and deployment easier.

Before the Spring framework, Java enterprise applications used the old Java EE architecture. The J2EE architecture was clunky and bulky. Due to enormous amounts of XML configurations and methods to be implemented, working with J2EE was painful and error-prone. Applications also had performance issues because the number of files required to run any application was huge.

To solve these problems and to make life easier for developers, they created the Spring framework.  

  • Spring is packed with features but is lightweight.
  • It follows all the best practices for coding.
  • Spring is modularized. Even though Spring has many components, you need to worry about only the modules required by your application. This setup helps to keep the number of files needed to a bare minimum.  
  • Spring enables POJO-driven development, which allows us to use robust, better-performing web containers instead of EJB container products.
  • Spring uses most of the existing technologies like ORM frameworks, loggers, etc
  • Testing a Spring application is easy.
  • Spring’s web framework is an MVC framework that segregates code well.
  • Spring provides a transaction management interface that scales well.
  • It has excellent documentation to aid development.

Due to all these reasons, Spring is now the preferred framework for web-based Java applications.

A key element of Spring is infrastructural support at the application level: Spring focuses on the “plumbing” of enterprise applications so that teams can focus on application-level business logic, without unnecessary ties to specific deployment environments.

Spring documentation.

3. Download

To download the Spring framework, we need to the Spring repository and find the latest version. Clicking on the link takes us to the next page to download the zip containing the newest jar files. At the time of the article, the latest version is 5.3.4.  The zip that gets downloaded is spring-5.3.4-dist.zip. You can extract the zip in a location of your choice. The spring framework is not ready to use on our system.

download spring framework jars - Spring Download Repository
Spring Download Repository

4. Setup and Prerequisites

To check the jar, we will set up and use the Spring, a simple application. To be able to use the Spring jars, we will need the following:

  • Java version 8 and above. I am using Java version 15.
  • An IDE. I am using the Eclipse IDE.
  • Spring Jars downloaded.

Depending on the IDE, the options may change. However, the steps for setting up Spring are the same. The Prerequisite steps before we start coding are as follows:-

  • Create a new Java Project in Eclipse.
  • Right-click on the Project and then select Build Path.
  • In the Build Path options, select the Configure Build Path.
  • Select all the Spring jars from the extracted zip file as External jars into the project.
  • Click on Apply and Close button.
download spring framework jars - Eclipse Build Path
Eclipse Build Path

Below are all the jars we require. The zip comes with their respective source and Javadoc jars as well. Those jars are optional and not mandatory for running the application.

download spring framework jars - Spring Jars
Spring Jars

5. Verify install

To Verify that the spring framework is set up properly on our system, we will create a simple Hello World application with the Spring Framework. We will use the Java-based configuration instead of an XML-based configuration. We use annotations for doing so. The main class of the application is ApplicationClass.java. In the main class, we initiate the ApplicationContext and call the methods of our Bean Class.

The HelloWorld.java is a Bean class which is a class managed by the Spring Inversion of Control container. We define a Bean by using the @Bean annotation. Bean classes are annotated in the Configuration class. We use a class @Configuration annotation to mark a java file(class) as the Configuration class. In our example, the HelloWorldConfigClass.java is the Configuration class. A Configuration class tells Spring framework that it contains the bean definition methods annotated with the @Bean annotation.

The Bean

HelloWorld.java

package com.jcg.springmvc.examples;

public class HelloWorld {
	private String message;
        public void setMessage(String message){
	      this.message  = message;
	}
	public void getMessage(){
	      System.out.println(message);
	}
} 

The Main Java Class

ApplicationClass.java

package com.jcg.springmvc.examples;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class ApplicationClass {
	
	private static ApplicationContext ctx;

	public static void main(String[] args) {
		//The Context object differs on the basis of whether we are using Annotations or xml.
		ctx = new AnnotationConfigApplicationContext(HelloWorldConfigClass.class);

		HelloWorld helloWorld = ctx.getBean(HelloWorld.class);
		helloWorld.setMessage("Rise and Shine!!");
		helloWorld.getMessage();		
	}
}

The Configuration class

HelloWorldConfigClass.java

package com.jcg.springmvc.examples;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

//This is a class-level annotation
@Configuration
public class HelloWorldConfigClass {

	 @Bean 
	   public HelloWorld helloWorld(){
	      return new HelloWorld();
	   }
}
download spring framework jars - Output of the application
The Output of the application

6. Summary

We looked at how to download and set up the spring framework in our system. We also saw a simple application to verify that we have installed our jars correctly. To understand all the terms related to the application, please refer to the documentation.

7. Download the Source Code

That was a tutorial on how to download spring framework jars.

Download
You can download the full source code of this example here: How to Download Spring Framework JARs

Reshma Sathe

I am a recent Master of Computer Science degree graduate from the University Of Illinois at Urbana-Champaign.I have previously worked as a Software Engineer with projects ranging from production support to programming and software engineering.I am currently working on self-driven projects in Java, Python and Angular and also exploring other frontend and backend technologies.
Subscribe
Notify of
guest

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

1 Comment
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Samuel
Samuel
1 year ago

Thank you

Back to top button