Spring Boot-Series Part 1: Setting up the maven based Spring boot application in STS or Eclipse IDE

We can create a simple spring boot project with spring initialzr or directly in STS.

We will use spring initializr for this tutorial to create an simple spring boot project.

Required softwares are:

  • Java JDK
  • STS 4
  • Maven 3.5
  • Postman

Let us get started. 🙂

Step 1: Go to https://start.spring.io/

Step 2: Fill the details like Project type as Maven, Spring boot version, Metadata, Add Dependencies as shown below and click on Generate

Step 3: Download the Zip and unzip the contents at any new folder

Step 4: Open STS

Step 5: Click on FILE > Import > Existing Maven Project

Step 6: Browse to your project’s directory and then click on Finish

This will start importing your maven spring boot project in the STS workspace and start downloading the dependencies from from maven central repo

You can open the pom.xml file check all the dependencies listed, you can modify according to your project’s requirements

Step 7: Build your application with maven install

After this all the dependencies will be downloaded into .m2 folder in your users directory and Build will be success with required passed test cases!

Let us run the application!

But before that let us add a controller class first!

Create a package and add the controller class as shown below:

@RestController	
public class EmployeeController {

	@RequestMapping("/hi")
	public String helloWorld() {
		return "Greetings from Spring Boot! Greetings from thewebspark.com!";
	}
@SpringBootApplication
@ComponentScan(basePackages="com.thewebspark.EmployeeRecords")
public class EmployeeRecordsApplication {

	public static void main(String[] args) {
		SpringApplication.run(EmployeeRecordsApplication.class, args);
	}

Modify the application class as above too..

Now let us run the application, go to Run As > Spring Boot App

Application will start running!

Now go to POSTMAN and create a GET request and give URL as localhost:8080 or you can check in browser too.

So this is how your spring boot app is ready to go. You can add some junit unit test cases using mockito framework or any other framework.

Find the full code on this Github

Advertisement

One thought on “Spring Boot-Series Part 1: Setting up the maven based Spring boot application in STS or Eclipse IDE

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s