Skip to main content

Creating Simple Hello World Application with SPRING BOOT

For creating a simple running web application with spring boot we do not have to do much. We just require to follow some simple steps and we are good to go. Unlike SpringMVC framework we do not. have to take care of all heck of configuration or XML file in one go we are all set with working mvc based web application.

Now we have to follow these steps.

  • Generate spring boot project from this url "https://start.spring.io/" You can do the same using STS setting to.
  • Importing the project in STS.
  • Create a RestController for our url.
  • Running the web application.
Just by following above two steps we will be able to create our simple working web application. Isn't it simple.

Now Let's get going.

Step 1: Generate the spring boot project from this url https://start.spring.io/".


Browse to https://start.spring.io/ site and there you will get following screen.



  • Select "Maven Project" from the drop down if you are going to develop maven  project or you can choose gradle build tool for you. In this tutorial we will be going use using maven as our build tool.
  • Select "JAVA"  from the second dropdown.
  • Select version for spring boot we are using 2.0.0 at the time of development of this tutorial.
  • Edit the group as "com.learn.demo" this will be the package structure when your spring boot application will be generated.
  • Give the artifact name ex :"springboot" then your package will look like something as "com.learn.demo.springboot" this will be yours base package.
  • In search dependencies section we will be add required dependences required for our project. Here just type "web" and select the selection form the dropdown as bellow.




Now click on "Generate Project" Button. This will download the generate project to your computer.Now all you. have to is to extract this dowloaded file and and import it in "STS".

Step 2:  Importing project to "STS"


Now, go to your STS and and under file section click on import for importing your generated spring boot project.


and select  "existing maven project". From the window appreared.


Now. Browse to your project location and select the project.


after clicking on import you have successfully imported the spring Boot project to your STS.

After importing the project to STS your project structure will look like this.

Now build the Maven project using "mvn clean install". For this command to work you should have mvn configured to your computer. After the build is successful our are ready to add controller.

Step 3: Add Controller to your project.

 Now, create a class "AppController" in "com.learn.demo.springboot" package. and write this code to it.





Here we have annotated this "AppController" class as restController using @restConroller.

Explanations.
@RestController - This is restful webservices controller  and used to return object in form of JSON/XML and write the response to Http.This specifies that that response the method will be returning  is JSON/XML response not the view response.

@RequestMapping - This Annotation for mapping web requests onto methods in request-handling classes. Any request coming to "https://localhost:8080/" will land on "index()" method. and this index method will give "Hello there! This is index page." message.

Now we are all set to launch our app and test. 

Step 4 :  Running the Spring Boot Application.


To run spring boot application right click on the project got to "run->spring boot app". 

Your application will start and  on port 8080 . This is default port specified by spring boot application.


Now go to your any browser and hit this url "https://localhost:8080/"  you will get the following output.



Thanks for reading this tutorial. If you  all readers have any suggestions please comment below.



Comments

Popular posts from this blog

Adding Spring-Security to Spring-Boot App

In the previous post we have created a simple spring boot application. This application was very simple application just getting request and showing page for requested URL. Currently all urls are open to all user that is we do not have any kind of authentication on the URL. Our spring boot application is like the open pool in which any one can come and start fishing. Now we want to secure our application so that only authenticated user will be able to visit secure part of the application. For this purpose we will be using the Spring Security. 
Scope of this tutorial. In this we will learn basic integration of spring security with spring boot.
NOTE: This tutorial will just contain only basic integration of spring security. If you haven’t gone through previous tutorial and you are the newbies to this spring boot then I will request you to go through previous post to get understanding of spring boot. 
Now lets get started with the configuration.If you do not have the previous code you can …

About Me

I am a self motivated full stack  developer. I have worked in many projects under several companies.
Java is one of my favourite language. Currently i am working with Tata Consultancy Services, Hyderabad. Tata Consultancy is my first company where i started my career on 24th Oct 2016.

Currently i am working on spring mvc in TCS but i also have a knowledge of Spring Boot, Angular, MongoDB. reqularly i am trying to add extra beauty to my profile. For this i believe in learn and unlearn strategy.

Reason for developing this blog is to show case my work and keep me busy during the weekends. Yahh! its true i have lot of free time on weekends as i don't have any girlfriend to waste my time with. And so i created this blog to show case my learning and work. Now, this blog gives me a goal to pursue and the way to keep me busy.

Through this blog i will try to share to all readers that i will be learning in course of time. I will try to keep this blog updated with latest evolution in develo…