0

We generally define our main application class in a root package above other classes.

The Spring Boot Application annotation in the main application class implicitly loads other classes as its the base package.

MY Question my main class is in com.example.main my controller class package is com.example.controller

when i run as Spring boot app, application is loaded but the rest API throws 404, how to configure parallel

ShasiSekar
  • 63
  • 1
  • 9
  • Possible duplicate of [@RestController in other package doesn't work](https://stackoverflow.com/questions/33039774/restcontroller-in-other-package-doesnt-work) – Madhu Bhat Mar 11 '19 at 15:34
  • Just add `@ComponentScan(basePackages = { "com.example","com.example.controller"} )` where you're having `@SpringBootApplication` – Madhu Bhat Mar 11 '19 at 15:36
  • Thank you @Madhu Bhat, I have interfaces for Spring JPA, had to include @EnableJpaRepositories("com.example.repository") to make it work – ShasiSekar Mar 12 '19 at 06:51

1 Answers1

1

As your main class is not in root package, you need to annotate @componentScan in your main class as below.

@SpringBootApplication
@ComponentScan({"com.example.controller"})
public class SpringBootApplication {
//...your code.
}

In case you want to scan all the sub-class you need to pass the root package path in componentScan

 @ComponentScan({"com.example"})
Nishant Bhardwaz
  • 924
  • 8
  • 21