TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

Creating Spring Boot Project Using STS

Creating Spring Boot Project Using STS with Introduction, Features, Project, Starter Project Wizard, CLI, Application, Annotations, DM, Properties, Actuator, Thymeleaf View, JPA, JDBC etc

<< Back to CREATING

Creating a Spring Boot Project Using STS

We can also use Spring Tool Suite to create a Spring project. In this section, we will create a Maven Project using STS.

Step 1: Open the Spring Tool Suite.

Step 2: Click on the File menu -> New -> Maven Project

Creating Spring Boot Project Using STS

It shows the New Maven Project wizard. Click on the Next button.

Creating Spring Boot Project Using STS

Step 3: Select the maven-archetype-quickstart and click on the Next button.

Step 4: Provide the Group Id and Artifact Id. We have provided Group Id com.TheDeveloperBlog and Artifact Id spring-boot-example-sts. Now click on the Finish button.

Creating Spring Boot Project Using STS

When we click on the Finish button, it creates the project directory, as shown in the following image.

Creating Spring Boot Project Using STS

Step 5: Open the App.java file. We found the following code that is by default.

App.java

package com.TheDeveloperBlog;
public class App 
{
public static void main( String[] args )
{
System.out.println( "Hello World!" );
}
}

The Maven project has a pom.xml file which contains the following default configuration.

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.TheDeveloperBlog</groupId>
<artifactId>spring-boot-example-sts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-example-sts</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Step 6: Add Java version inside the <properties> tag.

<java.version>1.8</java.version>

Step 7: In order to make a Spring Boot Project, we need to configure it. So, we are adding spring boot starter parent dependency in pom.xml file. Parent is used to declare that our project is a child to this parent project.

<dependency>
 <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
</dependency>

Step 8: Add the spring-boot-starter-web dependency in pom.xml file.

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>

Note: When we add the dependencies in the pom file, it downloads the related jar file. We can see the downloaded jar files in the Maven Dependencies folder of the project directory.

Creating Spring Boot Project Using STS

After adding all the dependencies, the pom.xml file looks like the following:

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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.TheDeveloperBlog</groupId>
<artifactId>spring-boot-example-sts</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>spring-boot-example-sts</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>  
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.1.RELEASE</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>2.2.1.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>

Step 9: Create a class with the name SpringBootExampleSts in the package com.TheDeveloperBlog.

Right-click on the package name -> New -> Class -> provide the class name -> Finish

Creating Spring Boot Project Using STS

Step 10: After creating the class file, call the static method run() of the SpringApplication class. In the following code, we are calling the run() method and passing the class name as an argument.

SpringApplication.run(SpringBootExampleSts.class, args);  

Step 11: Annotate the class by adding an annotation @SpringBootApplication.

@SpringBootApplication

A single @SpringBootApplication annotation is used to enable the following annotations:

  • @EnableAutoConfiguration: It enables the Spring Boot auto-configuration mechanism.
  • @ComponentScan: It scans the package where the application is located.
  • @Configuration: It allows us to register extra beans in the context or import additional configuration classes.

SpringBootApplicationSts.java

package com.TheDeveloperBlog;
import org.springframework.boot.SpringApplication;  
import org.springframework.boot.autoconfigure.SpringBootApplication; 
@SpringBootApplication  
public class SpringBootExampleSts 
{
public static void main(String[] args)
{  
SpringApplication.run(SpringBootExampleSts.class, args);  
} 
}

Step: Run the file SpringBootExampleSts.java, as Java Application. It displays the following in the console.

Creating Spring Boot Project Using STS

The line Started SpringBootExampleSts in 5.038 seconds (JVM running for 6.854) in the console shows that the application is up and running.



Next TopicSpring




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf