annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

We Are Going To Discuss About annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}. So lets Start this Java Article.

annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

  1. annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    In your case roomDao is a bean which has to create while initializing. But in your case you are just scanning controllers,so only controller bean will be created not others which present other than com.Room.Controller package.

  2. annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}

    In your case roomDao is a bean which has to create while initializing. But in your case you are just scanning controllers,so only controller bean will be created not others which present other than com.Room.Controller package.

Solution 1

Document : context component scan is used scan for classes(annotated) to create beans.

In your case roomDao is a bean which has to create while initializing. But in your case you are just scanning controllers,so only controller bean will be created not others which present other than com.Room.Controller package.

 <context:component-scan base-package="com.Room.Controller" />

So make it to scan all annotated classes. Then all required(annotated) beans will be created and BeanCreationException will go.

Original Author Prasanna Kumar H A Of This Content

Solution 2

Most of the times when you develop a springboot application and perform dependency injection in other classes, you get an error stating

{@org.springframework.beans.factory.annotation.Autowired(required=true)}

This is because the Main of the application resides in a package for example
(com.example.project)

and your other packages have a different naming structure such as

com.example.entites,
com.example.services,
com.example.repositories

And hence, your (main class) cannot find these other packages automatically.

What you have to do to resolve this problem, is to name your other packages to follow the (main) package structure, so it scans them automatically, so you have the error bean problem resolved.

So now our package structure will have to be (refactored) and (renamed) as follows:

com.example.project.entities
com.example.project.services
com.example.project.repositories

And voila!!!, the main class scans all the other packages automatically, since it is within its folder.

Don’t forget, (a package) is a folder, hence, all the other (packages) are stored within the (package) and hence, it can easily find the other folders within it.

Original Author Nathaniel Cobbinah 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