Rishabh Sharma
Rishabh Sharma

Reputation: 33

Spring Boot 404 Error with Simple Controller

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:

enter image description here

enter image description here

enter image description here

Any help would be appreciated.

And I know @SpringBootApplication automatically take all the annotation.

Upvotes: 0

Views: 800

Answers (3)

Erick Borda
Erick Borda

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

Carlos
Carlos

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

Anil Kumar Athuluri
Anil Kumar Athuluri

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

Related Questions