A Developer Gateway To IT World...

Techie Uncle Software Testing Core Java Java Spring C Programming Operating System HTML 5 Java 8 ES6 Project

Add Controller in Spring Boot

how to add rest controller in spring boot?

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;

    public class MainClassForSpringBootApp {

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

        // creating an endpoint
        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.