Site icon NgDeveloper

Create Your First Spring Starter Project From start.spring.io

By default you should be able to see the below UI in start.spring.io:

Add the Dependencies

I am going to add the dependencies required to develop the REST API’s.

Extract this demo.zip and import as maven project in STS/Eclipse

After the Extract

Right click on Project Explorer and click import

First time, it takes some time to pull all the maven dependencies

Right Click on the demo project Run As -> Maven build... and then type clean install

You should be able to see Build Success

Right click -> Run As -> Spring Boot Project

Spring Boot Maven Application is started successfully,

You should be able to see this then you spring boot application is running without any issues

Now, create SearchController.java with the below content,

package com.example.demo.controller;

import java.util.ArrayList;
import java.util.List;

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

@RestController
@RequestMapping("/v1/search")
public class SearchController {

	@GetMapping("/popular")
	public List<String> getPopularSearchList() {
		List<String> popularSearchList = new ArrayList<>();
		popularSearchList.add("Mobile");
		popularSearchList.add("Laptop");
		popularSearchList.add("Headset");
		popularSearchList.add("Formal Shirts");
		return popularSearchList;
	}

}

Now hitting this url (http://localhost:8080/v1/search/popular) in chrome / postman gives the below response,

["Mobile","Laptop","Headset","Formal Shirts"]

Exit mobile version