Search code examples
springspring-restcontrollerspring-rest

Why does the package matter for Spring RESTful controller classes


I have the Spring sample RESTful server running. If I add controller classes to the com.example.restservice package, they work. But if I put the same class in the package net.windward.RESTfulEngine.Controllers - they are not found.

I don't see any setting anywhere. What is limiting where these controllers need to be located?


Solution

  • Spring starts scanning the packages from the main package that your @SpringBootApplication class exists and all of its sub-packages.for your case you need to use @ComponentScan in order to scan external packages.