• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

org.springframework.beans.factory. UnsatisfiedDependencyException when autowiring

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am having an issue when publishing my project to my server, I have tried several solutions and I couldn't make it work, I have all annotations in place and the XML configuration done correctly as well.

UserController.java

   

UserServiceImpl.java

 

UserDAOImpl.java

   

UserDetailsServiceImpl.java

   

db-config.xml

   

dispatcher-servlet.xml

   
 
 
Paul Herrerias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
web.xml

   

The exception I get:

     
 
Ranch Hand
Posts: 188
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It says in the error log:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.prh.tracking.dao.iface.UserDAOIface' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations:
{@org.springframework.beans.factory.annotation.Autowired(required=true), @org.springframework.beans.factory.annotation.Qualifier(value=userDAO)}
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoMatchingBeanFound(DefaultListableBeanFactory.java:1506)
 
Bartender
Posts: 669
15
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The problem might be because of the qualifier names.
 
Al Hobbs
Bartender
Posts: 669
15
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also you didn't post the code for UserDAOIface.  Does that even exist?
 
Paul Herrerias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is the code:



And why would the qualifier names be the issue?
 
Sheriff
Posts: 22862
132
Eclipse IDE Spring TypeScript Quarkus Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You require the injected UserDAOIface to have name userDAO, but you never give the actual bean that name. That's why the autowiring fails. There are two solutions:
1) Remove the @Qualifier annotation.
2) Specify the name in the @Repository annotation.
 
Paul Herrerias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I use the Qualifier name because I autowire UserDAOIface twice and therefore I get this:



And I do not know how to specify the name in the @Repository annotation.
 
Al Hobbs
Bartender
Posts: 669
15
TypeScript Fedora
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't need to even use qualifier unless you have more than one bean of the same type.
 
Paul Herrerias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Al Hobbs wrote:You don't need to even use qualifier unless you have more than one bean of the same type.



I know, and I autowire 2 beans of the same type UserDAOIface that's why I am using Qualifier besides I already tried to remove them and I showed what I get.
 
Ranch Hand
Posts: 93
1
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul,

Here is a series of steps that will fix your problem:

1. Use a better naming convention; ie, stick to camel-case.  Rename your interfaces to: UserDao, UserService.
2. Even though you are autowiring UserDao twice, you still use the singleton instance created by the Spring container.
3. Remove @Qualifier annotation; it is not needed.
4. Remove line 41 from db-config.xml, since Component scanning will create this bean anyway.
5. In Web.xml remove lines 38-41.  You've already created a ContextLoaderListener in lines 20-23
 
Paul Herrerias
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Nachreiner wrote:Paul,

Here is a series of steps that will fix your problem:

1. Use a better naming convention; ie, stick to camel-case.  Rename your interfaces to: UserDao, UserService.
2. Even though you are autowiring UserDao twice, you still use the singleton instance created by the Spring container.
3. Remove @Qualifier annotation; it is not needed.
4. Remove line 41 from db-config.xml, since Component scanning will create this bean anyway.
5. In Web.xml remove lines 38-41.  You've already created a ContextLoaderListener in lines 20-23



This worked but now I am getting a whole different error, if this can be replied here please, help me if not, I will create a new topic, I must say this is the first time I am working with Hibernate therefore there are some concepts I miss:


 
Tim Nachreiner
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm guessing it's something in the UserController.
Line 11 looks suspicious; it doesn't return anything.
Try this:
comment out line 11
change line 12 to model.addAttribute("user", userService.getUser(authentication.getPrincipal.getName()));
 
Tim Nachreiner
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot the braces on the getPrincipal function.....

model.addAttribute("user", userService.getUser(authentication.getPrincipal().getName()));
 
Tim Nachreiner
Ranch Hand
Posts: 93
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here's a better solution:

 
reply
    Bookmark Topic Watch Topic
  • New Topic