How to add Rest Controller in Spring Boot?
Spring Boot Startup example:-
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@SpringBootApplication
@RestController
public class MainClassForSpringBootApp {
public static void main(String[] args) {
SpringApplication.run(MainClassForSpringBootApp.class, args);
}
// creating an endpoint
@GetMapping("/Hi")
public String GreetingMsg() {
return "Welcome to techieuncle.com";
}
}
Now run the main class and watch till the console as Tomcat started on port(s): 8080 (http) with context path ''
Now open chrome and test endpoint as http://localhost:8080/Hi
output will be Welcome to techieuncle.com
RestController provides rest api.