Reputation: 33
I am trying to make a simple Spring Boot Application with the simple controller (Restful controller) where the function is returning the String that is to be printed on the Web page. But I am facing a problem where I am getting 404 error every time. In my views, I am setting up the application right. I have just used spring-boot-starter-web as the dependency.
Application file:
Any help would be appreciated.
And I know @SpringBootApplication automatically take all the annotation.
Upvotes: 0
Views: 800
Reputation: 21
Need to add @ComponenScan the resquest to http:localhost:8080/api should return "Hello" if you need to add a path http:localhost:8080/user/api do as follow:
@RestController
@RequestMapping(value = "/user")
Upvotes: 0
Reputation: 834
Can you show me the structure of your project?, I believe the problem Spring is not finding your userController, @SpringBooApplication use the @ComponentScan how is in charge to search for all the spring annotations un your code, so I believe is something
Upvotes: 0
Reputation: 653
Either your controller class needs to be in or sub package of SpringBoot Application class or the package in which controller class exists needs to be scanned explicitly using @ComponentScan to resolve this
Upvotes: 1