file : CourseApiApp.java
package io.javabrains.springbootstarter;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class CourseApiApp {
public static void main(String[] args){
//this is the first step to convert the application into spring app
SpringApplication.run(CourseApiApp.class,args);
}
}
File HelloControllerTwo
package io.javabrains.springbootstarter.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/hello")
public class HelloControllerTwo {
public String sayHi() {
return "Hi";
}
}
I have created a very basic spring app to get hi on /hello path. I but I am still getting a fallback /error message on /hello
Could anyone please let me know what am I doing wrong?
Your @RequestMapping
annotation should be on your method, not your class.
You should also specify a method in your annotation.
Try this:
@RestController
public class HelloController {
@RequestMapping(value = "/hello", method = RequestMethod.GET)
public String sayHello() {
return "Hello";
}
}