首页 > 代码库 > Consider defining a bean of type 'package' in your configuration [Spring-Boot]

Consider defining a bean of type 'package' in your configuration [Spring-Boot]

 

https://stackoverflow.com/questions/40384056/consider-defining-a-bean-of-type-package-in-your-configuration-spring-boot

 

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."

 

 

 

 

 

 

I am not sure if it is because I have my project broke down in modules but this is how I solved my issue of not be able to find my repositories.

@SpringBootApplication@ComponentScan({"com.delivery.request"})@EntityScan("com.delivery.domain")@EnableJpaRepositories("com.delivery.repository")

Consider defining a bean of type 'package' in your configuration [Spring-Boot]