Skip to content
Advertisement

Spring cannot create UserService bean

Dao tier. I have abstract jpa dao interface, extended interface, and I added abstract implementation, from which I extend other real used implementations. These classes as follows:

JavaScript
JavaScript
JavaScript
JavaScript

Service tier. Here I also have abstract service interface, one extended interface (UserService) and its abstract and real implementations:

JavaScript
JavaScript
JavaScript
JavaScript

In my real project I got many extended interfaces from AbstractDao and AbstractServie. You can see the actual hierarchy: enter image description here

I can’t understand why spring can’t create @Service annotated beans and autowire those in my Controllers. Any help would be appreciated.

Advertisement

Answer

I took the liberty to look into your project in github https://github.com/tuanalexeu/JavaSchoolFinalTask

The problem is how you initialize your spring contexts, The AppConfig context is not read at all. This context has all your configurations.

By modifying your initializer to include your AppConfig as root, all beans should be present in the same context. (You can also choose to have parent -> child contexts as well, but that too should be done in the initializer). Hope it helps. Good luck.

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement