First Spring Boot Application in STS

Hello everyone, in this article we will see, how we will start to develop a simple spring boot application in Spring Tool Suite environment(STS).

First open sts then we will create a new project.

File-> New -> Spring Starter Project



Then we will add the dependencies. Here I added Spring Web dependency. Adding dependency is very simple. Choose Spring Web which is shown in the following figure. Then click on Next button.



Then click on Next button and then click on Finish button.



Now a project structure created named as FirstSpringBootDemo.


Our Required Files:

pom.xml
FirstSpringBootDemoApplication.java
TestController.java
pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>3.0.1</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>FirstSpringBootDemo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>FirstSpringBootDemo</name>
    <description>Demo project for Spring Boot</description>
    <properties>
        <java.version>17</java.version>
    </properties>
    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</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>

FirstSpringBootDemoApplication.java

package com.test;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class FirstSpringBootDemoApplication {

    public static void main(String[] args) {

        SpringApplication.run(FirstSpringBootDemoApplication.class, args);
    }

}

TestController.java

package com.test.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class TestController {
    @RequestMapping("/rama")
    @ResponseBody
    public String show()
    {
        return "JAVA means Silan Software";
    }
}

Output :
To run this application, right click on FirstSpringBootDemoApplication.java -> Run As -> Java Application, then we get:


Then open any browser and enter the following url
http://localhost:8080/rama

We will get:



About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext