Consider defining a bean of type 'package' in your configuration [Spring-Boot]
Solution 1:
It might be because the project has been broken down into different modules.
@SpringBootApplication
@ComponentScan({"com.delivery.request"})
@EntityScan("com.delivery.domain")
@EnableJpaRepositories("com.delivery.repository")
public class WebServiceApplication extends SpringBootServletInitializer {
Solution 2:
There is a chance...
You might be missing @Service
, @Repository
annotation on your respective implementation classes.
Solution 3:
Your Applicant class is not scanned it seems. By default all packages starting with the root as the class where you have put @SpringBootApplication
will be scanned.
suppose your main
class "WebServiceApplication" is in "com.service.something
", then all components that fall under "com.service.something
" is scanned, and "com.service.applicant
" will not be scanned.
You can either restructure your packages such that "WebServiceApplication" falls under a root package and all other components becomes part of that root package. Or you can include @SpringBootApplication(scanBasePackages={"com.service.something","com.service.application"})
etc such that "ALL" components are scanned and initialized in the spring container.
Update based on comment
If you have multiple modules that are being managed by maven/gradle, all spring needs is the package to scan. You tell spring to scan "com.module1" and you have another module which has its root package name as "com.module2", those components wont be scanned. You can even tell spring to scan "com" which will then scan all components in "com.module1.
" and "com.module2.
"
Solution 4:
Basically this happens when you have your Class Application in "another package". For example:
com.server
- Applicacion.class (<--this class have @ComponentScan)
com.server.config
- MongoConfig.class
com.server.repository
- UserRepository
I solve the problem with this in the Application.class
@SpringBootApplication
@ComponentScan ({"com.server", "com.server.config"})
@EnableMongoRepositories ("com.server.repository") // this fix the problem
Another less elegant way is to: put all the configuration classes in the same package.