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

We Are Going To Discuss About Consider defining a bean of type ‘package’ in your configuration [Spring-Boot]. So lets Start this Java Article.

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

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

    There is a chance…
    You might be missing @Service, @Repository annotation on your respective implementation classes.

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

    There is a chance…
    You might be missing @Service, @Repository annotation on your respective implementation classes.

Solution 1

Advertisements

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 {

Original Author Mike3355 Of This Content

Solution 2

Advertisements

There is a chance…
You might be missing @Service, @Repository annotation on your respective implementation classes.

Original Author CodeWorld Of This Content

Solution 3

Advertisements

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.

Original Author ameenhere Of This Content

Solution 4

Advertisements

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.

Original Author Carlos Marcano Of This Content

Conclusion

So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment