Issue
I have created demo Spring Boot project and implemented Restful services as shown here
@RestController
public class GreetingsController {
@RequestMapping(value="/api/greetings", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<String> getGreetings(){
return new ResponseEntity<String>("Hello World", HttpStatus.OK);
}
}
When I tried to invoke the service with Postman tool with url "http://localhost:8080/api/greetings" as request method GET, I am getting below error message
{
"timestamp": 1449495844177,
"status": 404,
"error": "Not Found",
"message": "No message available",
"path": "/api/greetings"
}
Per Spring Boot application, I don't have to configure the Spring Dispatcher servlet in web.xml.
Can someone help me to find out the missing point here?
Solution
You're probably missing @SpringBootApplication
:
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class Application {
public static void main(String[] args) throws Exception {
SpringApplication.run(Application.class, args);
}
}
@SpringBootApplication
includes @ComponentScan
which scans the package it's in and all children packages. Your controller may not be in any of them.
Answered By - cahen