Spring boot hello world
Tags: java, maven, spring, beginners
Published: 2021-08-27 09:21:45

Hi everyone, today we're writing a hello world project in spring-boot application. I had always loved java as a programming language, and I wanted to expand my skill set in the domain. Recently, we were given a task to write a basic application of CRUD operations in spring boot, but let's keep that for another day. 

Today, we'll learn how to start with this amazing technology framework. Let's begin!

## Tools you need:
- **java version 1.7** or above: You can check that by writing ```java -version``` inside your terminal or command prompt.
- **Eclipse IDE**: [Eclipse download](https://www.eclipse.org/downloads/) Go for Java EE version.
- **Maven or Gradle**: For this tutorial, I'll be going with Maven. Check your maven version ```mvn -v```

Here's the screenshot for reference:
![Screenshot of what output of above commands should look like](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/s1c61xbezz202ekz1zwp.png)

## Steps to follow:
- Go to [Spring starter kit](https://start.spring.io). It is by far the most comprehensive way to get started with a spring application.
![start.spring.io landing page](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gsjb9eqzd74rjzbs5icv.png)
- Fill in group, artifact ID (most probably, your project name) and description (optional). Also, don't forget to check the spring version, although you need not to worry as it is checked to the latest stable one by default.
- Add dependencies, by clicking the button on right top side. Type in web, then select spring web. Have a look at below screenshots for reference;
![Add dependencies](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0brstirikcil8a6sa8aq.png)
![Spring web](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iax4jcuduszueo8mc22a.png)

- Click on generate, you'll see a .zip getting download with your artifact ID.
![Spring project downloaded](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/y7cbp0fh3a3m9xr60uwf.png)

- Extract the file and open Eclipse.

- Import the project using below steps:
File -> Import -> Existing Maven Project (you can type in the search box too) -> Next -> Browse -> Select the Project Folder -> Finish

- Now you should see your project in your project explorer as below:
![Project Structure](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rgj6jb28jm9lh214k1js.png)

- Now that we've our main application template ready, we need a controller class that'll control our application, as to what should my application should render or do upon handling a request. Basically, A controller controls the flow of the data. It controls the data flow into model object and updates the view whenever data changes.

- For this to achieve we create a package to associate our controller classes in a single package for easy and practical access. So, go to your project explorer and make a new package inside your 
> src/main/java

Now,give it a name and write your controller class as given below:
![Controller class](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hnts30cjw1ri3wq2dol3.png)

- Now let's add controller functions and annotations to give it a meaning.
![Controller class meaning](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fw0hfgbfx656sw51s018.png)
You can see the annotations ```RestController``` and ```RequestMapping``` 
RestController specifies that a RESTful web service is being created. RequestMapping maps the URL associated with the application and renders the function as per the requested URL. In this we've specified just the landing page("/")

- Start the project by clicking run as > java application.
Alternatively, you can choose spring boot suite in eclipse marketplace by which you can start and debug the application easily.
You'll see the hello world screen. Go on and have a look at __localhost:8080__