Spring Tools suit is an official IDE provided by the Spring. You can use it to create Spring application with minimum effort. This IDE is similar to your favourite IDE whether it is Eclipse, IntelliJ IDEA, or others.
When you will visit the site(spring), you will see couple of versions of IDE for different the variety of developers. You can select and download any to your local machine.
To download this IDE, use this official link https://spring.io/tools. The site looks like this:
Select the IDE for your platform such as Linux or Windows and click on it. This will start downloading executable application. After downloading, click on the installer and it will start installing to your local system.
I’m attaching some screenshot for your convenience. You can get idea by following these.
This is the first screen you will see while running the executable.
After that, it asks for the location to install the IDE. Select the location for the application in your local system, it can by any folder or drive like C or D or others.
After that, click on the launch button and it will start opening the IDE. It shows a progress bar that represents the percentage of process is done. This will look like this:
After completing the process, the IDE will be opened. Since we chose the Eclipse version of the IDE, it looks similar to Eclipse now you can create spring application.
This IDE provides all the features of Eclipse so you can create maven project or dynamic project as well. Apart from this, it provides one more option spring started project to create a spring project. This is similar to the online spring initializer tool that asks for the dependencies too during the project creation.
Let’s start by selecting the spring started project from the File menu. So, select that and create a spring app.
Click File->New->Spring Starter Project
Now, fill the project details such as project name, project type (maven in our case), java version, packaging, programming language, and etc.
In the group name, provide the name in reverse domain and then artifact name. Then, click the next button.
Now, it asks for dependencies. Since we are creating a simple spring app that does not require any dependencies, we will skip this for now and click finish.
This step is similar to the spring initializer that asks for the dependencies while creating project. You can select dependencies like: Web, JSON, JPA, MySQL Connector, etc.
Click on the finish button and it will create a spring application that looks like this:
The IDE may take some time to build the project so just wait for couple of seconds if the project is not ready. You can see the process bar in the bottom of the IDE.
After completing, you can explore the project that has several default folders and files.
This project has two main files, pom.xml and SpringApplication.java. The pom.xml file is an XML file that contains project configuration and list of dependencies. Similarly, the SpringApplication.java file contains java source code to execute the application. It contains a main() method as all Java project has and call to run() method to start the application.
We will explore this later in our next articles.
Initially, the code for java file looks like this:
// SpringApplication.java
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class SpringappApplication {
public static void main(String[] args) {
SpringApplication.run(SpringappApplication.class, args);
}
}
The pom.xml file looks like this:
// Pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.7.1</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.linuxhint</groupId>
<artifactId>springapp</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>springapp</name>
<description>spring application</description>
<properties>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
Run the Application
Now, it’s time to run the application. To do so, right-click on the project (current project) and select run like:
Run As->Java Application
It will trigger an event to execute the application.
You can see the running application status in the console tab at the bottom of the IDE.
Well, we have learned how to download, install, and setup the STS (Spring Tool Suit) IDE in local system. We created a spring application and successfully run as well.
In our next article, we will learn Dependency Injection concept that is most important concept of the Spring framework.