Signup/Sign In

Spring Project using STS

In this article, we are going to create a Spring project by using the STS tool. The STS (Spring Tool Suite) is an official IDE provided by the Spring foundation. We can use it to create spring applications. It is similar to the eclipse, if you are familiar with the eclipse then you will find it very easy to use. Let's start by downloading the STS and then creating the application.

To download the STS, you can visit the official site of the Spring or simply use this link(download STS). After downloading install it to your local system and then run.

Create a Spring Project

To create a Spring project, click on the File menu and select Project that further popup several project types such as Maven Project, Dynamic Project, Java Project, etc. Choose Maven Project because we used maven based spring project. For more details about creating Maven-based Spring Project read this article Maven Project.

After creating a project now, let's create a simple hello spring application. To create the application, we mainly created three files:




This project has a pom.xml file that contains configuration and project dependencies. You must add Spring Dependencies to this file to configure the application. After that, your project structure should look like below.

Project Structure:

Following will be the project structure of the new project created:

spring project using STS tool

Now let's see the code in each file one by one.

This file contains code for loading the application context file which is configured to load bean. Curious to know, what is Bean? Don't worry, we will cover it later in our tutorial. For now, just create this file.

package com.studytonight.example;
public class HelloWorld {
	public static void main(String[] args) {
		// loading the Bean and XML definitions from the given XML file
		ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
		HelloWorldService obj = context.getBean(HelloWorldService.class);

This file contains the code that will print the "Hello Spring" message to the console. Create this file with the "" name.

package com.studytonight.example;

public class HelloWorldService {
	public void hello() {
		System.out.println("Hello Spring!");


This is the configuration file for the Spring project. We can name it anything, but now save it as applicationContext.xml in your maven project.

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns=""
	xmlns:xsi="" xmlns:p=""
	xmlns:aop="" xmlns:context=""
	xmlns:jee="" xmlns:tx=""
	<context:component-scan base-package="com.studytonight.examples" />
	<bean id="helloWorldService"


This file is a part of the maven project and used to add dependencies for our project. For our project, we added spring dependencies. This is the latest by the time of this project. Although we can get these latest dependencies from the maven repository. Spring Dependencies.

<project xmlns=""

Run the Application:

Run this application (project) and get the below result. Since it is not a web application then we can run it simply as a Java application.

Hello Spring!

About the author:
I am a Java developer by profession and Java content creator by passion. I have over 5 years of experience in Java development and content writing. I like writing about Java, related frameworks, Spring, Springboot, etc.