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

Posted 再见理想

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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]的主要内容,如果未能解决你的问题,请参考以下文章

springboot Consider defining a bean of type 'xxx' in your configuration

Consider defining a bean of type 'org.springframework.security.authentication.AuthenticationMana

Consider defining a bean of type问题解决

MapStruct - Consider defining a bean of type in your configuration.

Consider defining a bean of type `xxx` in your configuration问题解决问题解决

Spring Boot @Autowired无法注入类 Consider defining a bean of type