Spring-boot Project – Part 1: First Setup

The season of spring.

Spring is around the corner, and for me personally, I have to better prepare myself for the new job that requires me to have some basic knowledge of the Java-powered framework. It’s time to get into it!

Okay, it’s been a while since I last updated my blog. March 2023 so far has been a roller-coaster ride since the very beginning of the month. Depressions, panic-attack, existential crises, and a lot… And most importantly, I’ll start a new job in April and it requires me to fully prepare myself for Java and Spring framework.

Java has always been my go-to language for my job and my side projects built for Android – both in java and Kotlin. But… Yes, there’s a big fat BUT – even though I’ve been using Java and Spring framework for the past three years, my current project only requires me to have some basic Java knowledge and not so much for the framework. It’s simply because my tasks revolve around making some modifications for already-existing classes and methods and that’s pretty much it.

So, it was less about building a class from scratch and most of the methods I had created were just minor modifications of those already written by someone else. Maybe this situation could be quite similar to some of the big tech companies’ employees, but this time, the story is a little different in my new job.

Sooooooo, I just decided to practice coding in Java and Spring framework all from scratch by watching some YouTube videos, other online materials, plus everyone’s favorite ChatGPT!

Without further adieu, let’s get into it, shall we??

First things first, go to Google and search “spring boot initializer”.

image 01

Then, select your items according to your environment.

*As of taking this screenshot, I used Java 1.8 but just realized it’s too old and most of the recent Eclipse versions were not compatible with it – so I eventually installed Java 17 LTS on my machine.

image 02

Then, take a look at the left section and click ADD DEPENDENCIES.

image 0

Search “web” and add it.

image 04

It’s now added. And we’ll need more dependencies.

image 05

Then, add the following items one by one.

image 06
image 07
image 08
image 09

Finally, it should look like this. Then, download it by clicking the GENERATE button.

image 10

In your local environment, create a new project in your favorite place on your PC and open it with Eclipse.

Following the steps: File -> Import

image 11

Search maven and select Existing Maven Project.

image 12

Select from the ‘browse’ section and find the recently downloaded project from Spring Initializer.

image 13

Select Finish

image 14

Open application.properties

image 15

Add the SQL database connection info just like this. In my case, I’m using MySQL.

spring.datasource.url=jdbc:mysql://xxx.xxx.xxx.xxx:3306/budget_tracker_db?useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=user_name
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

Then, let’s create a sample HTML index page.

Following the steps: templates -> new -> File

image 16

Create a new file “index.html”.

image 17

Then, add the following HTML.

<html>
<body>
Sample Screen
</body>
</html>

Go to your browser, and type:

localhost:8080

Then, you should see the following image on your browser.

Leave a Reply