enes

Enes Altınkaya

Spring Boot Hello World

Spring Boot Hello World

In this example, you will see how to start a Spring Boot application using maven.

  • Place the following block to your pom.xml.
<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>LATEST</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
</dependencies>

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

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
  • Create Application.class in a package, can not be in the default package.
@SpringBootApplication
public class Application {
    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}
  • Create HelloWorld.class.
@RestController
public class HelloWorld {
    @RequestMapping("/")
    public String index() {
        return "Hello World from Spring Boot!";
    }
}
Share on