DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • Using ZK With Spring Boot
  • How to Enable HTTPS on a Spring Boot Application
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project

Trending

  • Memory-Optimized Tables: Implementation Strategies for SQL Server
  • Intro to RAG: Foundations of Retrieval Augmented Generation, Part 1
  • Mastering Advanced Traffic Management in Multi-Cloud Kubernetes: Scaling With Multiple Istio Ingress Gateways
  • Designing AI Multi-Agent Systems in Java
  1. DZone
  2. Coding
  3. Frameworks
  4. Develop Web Application With Spring Boot in 30 minutes

Develop Web Application With Spring Boot in 30 minutes

Spring Boot is a popular Java-based web development framework. This tutorial help to develop the "Hello World" web application.

By 
Manish Gupta user avatar
Manish Gupta
·
Dec. 09, 20 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
14.4K Views

Join the DZone community and get the full member experience.

Join For Free

Spring boot is one of the most popular Java-based web application development frameworks. It helps develop applications rapidly as most of the application-specific configuration is taken care of by the framework. Spring boot also comes with an in-built servlet container, which helps run and test the application quickly. 

The following tutorial will help you quickly learn Spring Boot basics by creating a standard “Hello World” application. Let’s follow the quick tutorials with the basic assumption that Java8, maven, and eclipse are installed, and the reader knows their basic usage. 

Prerequisites

  • Java 1.8+  
  • Maven 

Let's install the Spring tools suite(STS) on Eclipse IDE to make development easier.

Install Spring Tool Suite

Go to Eclipse -> Help -> Market Place and search “Spring Tools” to install.

help menu


spring tools


Create a Project

After the Spring Boot tool installation, let us create a spring boot starter project named “HelloWorld” with the below configurations. The reader can give the project name as per their own choice.

creating a project

 

new spring starter project

Here latest available Spring Boot version, i.e., 2.4.0, is used with the following dependencies.

  1. Spring Boot DevTools – This tool helps in quick deployment of change without restart of server/container.
  2. Thymeleaf – This template tool is used for View component development.
  3. Spring Web – Required dependency for web application development.

 spring starter guide


Once the project is created, the project structure will look as below.

spring-workspace

Check Pom.xml

Let’s check the pom.xml and make sure its java version is set to 8.  

java.version

XML
 




xxxxxxxxxx
1
43


 
1
<?xml version="1.0" encoding="UTF-8"?>
2
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
4
    <modelVersion>4.0.0</modelVersion>
5
    <parent>
6
        <groupId>org.springframework.boot</groupId>
7
        <artifactId>spring-boot-starter-parent</artifactId>
8
        <version>2.4.0</version>
9
        <relativePath/> <!-- lookup parent from repository -->
10
    </parent>
11
    <groupId>com.hello</groupId>
12
    <artifactId>HelloWorld</artifactId>
13
    <version>0.0.1-SNAPSHOT</version>
14
    <name>HelloWorld</name>
15
    <description>Demo project for Spring Boot</description>
16
    <properties>
17
        <java.version>8</java.version>
18
    </properties>
19
    <dependencies>
20
        <dependency>
21
            <groupId>org.springframework.boot</groupId>
22
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
23
        </dependency>
24
        <dependency>
25
            <groupId>org.springframework.boot</groupId>
26
            <artifactId>spring-boot-starter-web</artifactId>
27
        </dependency>
28
        <dependency>
29
            <groupId>org.springframework.boot</groupId>
30
            <artifactId>spring-boot-devtools</artifactId>
31
            <scope>runtime</scope>
32
            <optional>true</optional>
33
        </dependency>
34
    </dependencies>
35
    <build>
36
        <plugins>
37
            <plugin>
38
                <groupId>org.springframework.boot</groupId>
39
                <artifactId>spring-boot-maven-plugin</artifactId>
40
            </plugin>
41
        </plugins>
42
    </build>
43
</project>



Check Main Class

Spring Boot framework will create the “HelloWorldApplication.java” class in the "com.example.hello” package. This class will be annotated with @SpringBootApplication. This is the entry point of the spring boot application.

Java
 




x


 
1
package com.example.hello;
2

          
3
import org.springframework.boot.SpringApplication;
4
import org.springframework.boot.autoconfigure.SpringBootApplication;
5

          
6
@SpringBootApplication
7
public class HelloWorldApplication {
8

          
9
        public static void main(String[] args) {
10
            SpringApplication.run(HelloWorldApplication.class, args);
11
        }
12
}
13

          



Run Project

As the "HelloWorld" project is created successfully, let's check it by running project as “Spring Boot App.”  This process will start the inbuilt servlet container and run the application. The application can be accessed at 8080 port.

run project

 spring boot project

Create Controller

Let’s create a Controller which will accept all the GET request as below.

hellocontroller


The controller class will have various annotation like @Controller, @GetMapping to handle incoming requests.

  1. @Controller: To inform Framework that this class is controller
  2. @GetMapping: To inform framework about GET request mapping for a specific path. Here the path is defined as “hello.”

Model is used to transfer data from Controller to View.

MVC design pattern is very standard pattern to develop the web applications. In this pattern, the Controller will receive the request, it will populate data with the help of the Model and transfer the control to a suitable View.

GetMapping

Create View

In our example, the Controller return “hello” string. This will force framework to redirect control to hello.html file available inside resource/templates directory.

hello.html

$hello

Themeleaf template engine is used to create "hello.html". With the help of Spring Boot DevTool, all changes are deployed to the container, i.e., changes like the creation of controller and view will be automatically pushed to container. 

Check "Hello World"

Let’s check the web application http://localhost:8080/hello.. If we observe the below response, then we have successfully completed the tutorials.

hello spring boot userCongratulations.

Hope this quick tutorial helped to develop basic understating of Spring Boot framework.

Code is available at https://github.com/mag1309/spring-boot-hello-world for reference.

Spring Framework Spring Boot Web application

Opinions expressed by DZone contributors are their own.

Related

  • Using ZK With Spring Boot
  • How to Enable HTTPS on a Spring Boot Application
  • Actuator Enhancements: Spring Framework 6.2 and Spring Boot 3.4
  • How Spring Boot Starters Integrate With Your Project

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!