Your First Spring Boot Web Application

In the previous example, we created a simple standalone application using the dependency spring-boot-starter. In this example, we will convert it into a simple web application with very minimal changes.

A Spring Boot application uses the @SpringBootApplication annotation over a class with a main method that will execute the application. The method call accepts two parameters — the class that actually contains the annotated @SpringBootApplication annotation and any application arguments. The ApplicationArguments interface allows you to access any application arguments. Spring Boot provides easy to use starter pom dependencies such as spring-boot-starter, spring-boot-starter-test, spring-boot-start-web.


Bean Components

We will use a simple bean class based on our previous examples. 

Within the bean file, we will use the annotation @RestController and @RequestMapping to expose the class as a service and to map to a url pattern. We will also change the signature of the bean's method to return a string that will be displayed in the browser.

package com.javajee.springboot;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

class JJWriter {
    public String write() {
        return "<h2>Inside JJWriter's method write()</h2>";


Test Class (Main class)

A Spring Boot application can be created using the annotation @SpringBootApplication.

We will cleanup the JJWriterMain method from the previous example and it will only have the method call.

package com.javajee.springboot;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class JJWriterMain {

    public static void main(String[] args) {, args);

Before executing the program, you must have also configured your Gradle/Maven dependencies.


Maven POM File

You need to add Spring Boot dependencies instead of Spring dependencies. Spring Boot provides easy to use starter pom dependencies such as spring-boot-starter, spring-boot-starter-test, spring-boot-start-web.

Only thing you will need to change in the pom.xml from the previous example is to change spring-boot-starter with spring-boot-start-web.

<project xmlns="" xmlns:xsi="" xsi:schemaLocation="">




Executing and verifying the program

You can execute the main class and verify the program by running http://localhost:8080/ in the browser. file

You can create a file called within the resources folder and Spring Boot will automatically pick it up. Please note that this file is not required for the current example, unless you need to change the default port for the embedded tomcat.

You can change the default port of the embedded tomcat server by adding below line to the file.

server.port = 8090

Now you can execute the main class and verify the program by running http://localhost:8090/ in the browser.

This may be required in case of any port conflicts or simply as a personal choice.


You did really good work. I really appreciate your new and different post. Please guys keep it up and share with us some unique post in the future…
iMac service center in Delhi
ipad service center in Kolkata

Was it useful?

Wishing you the best of luck for all your blogging efforts.This is my first opportunity to chat this website. I found some interesting things and I will apply to the development of my blog.
Engineering college in punjab
Engineering college in Chandigarh

Was it useful?

SCS is focused on providing the most comprehensive, heterogeneous, integrated IT Software solutions to enterprises around the world.
Two way SMS Gateway provider
Lakeside software
AMC Services

Was it useful?

I think the source code which you have provided here would be useful to all students who are studying java and doing projects in java. I have executed this source code and it worked successfully. Thank for sharing this. Expecting more useful codes like this. don julio real

Was it useful?

Solutions Middle East, works to Envision, Execute and Empower our clients by offerings design, implementation and on-going support services.
Messaging Solutions
Enterprise Data center
Business intelligence analytics for IT
IT Business Tracking System in UAE
Citrix Platinum Partner

Was it useful?

You have shared the complete details of Suntandy Chopin Piano. I think this post is very much enough to know the proper address and contact details of the branches. I am expecting more posts on this blog. Keep updating! ipad 2 wholesale

Was it useful?

Java is a very complicated subject for me. I am a regular visitor to your site to learn more about Java. Thanks for sharing such informative dish network channels article s with step step info about programming in Java. I appreciate your efforts. Thanks...

Was it useful?

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within!!!