'Rest Controller works just for Application class

I'm trying to do a getmapping method using rest-api which will return as a JSON on localhost: 8080. When I do this from the default Application class it works great but when I move this functionality to another class nothing happens. Could someone help me with this, please?

Application Class

BookController Class



Solution 1:[1]

Reason 1: Default Spring's component scanning can't fount your @RestController component, so you can try to do @ComponentScan directly.

Reason 2: You need to specify an endpoint for your @GetMapping by using @RequestMapping/@GetMapping("url") or both of them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Serhii Zhura