title: Error creating bean with name '*****': Injection of autowired dependencies failed
body: <pre><code>I am programming my first Java EE Hibernate/Spring application and an error appeared:
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userController': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void net.UserList.controller.UserController.setUserService(net.UserList.service.UserService); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'userDao' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.UserList.dao.UserDaoImpl
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
      org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:304)
      org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228)
      org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:300)
      org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:195)
  ......
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:748)
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Could not autowire method: public void net.UserList.controller.UserController.setUserService(net.UserList.service.UserService); nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'userDao' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.UserList.dao.UserDaoImpl
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredMethodElement.inject(AutowiredAnnotationBeanPostProcessor.java:596)
      org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87)
      org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185)
  ....
      java.lang.Thread.run(Thread.java:748)
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Cannot resolve reference to bean 'userDao' while setting bean property 'userDao'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.UserList.dao.UserDaoImpl
      org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:336)
      org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:108)
  ...
      org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:484)
      org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:136)
      javax.servlet.GenericServlet.init(GenericServlet.java:158)
      org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:506)
      org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
      org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:962)
      org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:445)
      org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1115)
      org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:637)
      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2555)
      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:748)
  root cause
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao' defined in ServletContext resource [/WEB-INF/dispatcher-servlet.xml]: Instantiation of bean failed; nested exception is java.lang.NoClassDefFoundError: Could not initialize class net.UserList.dao.UserDaoImpl
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1076)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1021)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:504)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475)
  ...
      java.lang.Thread.run(Thread.java:748)
  root cause
  
  java.lang.NoClassDefFoundError: Could not initialize class net.UserList.dao.UserDaoImpl
      sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
      sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
      sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
      java.lang.reflect.Constructor.newInstance(Constructor.java:423)
      org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:148)
      org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:89)
      org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateBean(AbstractAutowireCapableBeanFactory.java:1069)
      ...
      org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2544)
      java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
      java.lang.Thread.run(Thread.java:748)
  </code></pre>
  
  <hr>
  
  <p>My mvc-dispatcher-servlet.xml:</p>
  
  <p>http://www.springframework.org/schema/beans/spring-beans.xsd
          <a href="http://www.springframework.org/schema/context" rel="nofollow noreferrer">http://www.springframework.org/schema/context</a> <a href="http://www.springframework.org/schema/context/spring-context.xsd" rel="nofollow noreferrer">http://www.springframework.org/schema/context/spring-context.xsd</a> <a href="http://www.springframework.org/schema/tx" rel="nofollow noreferrer">http://www.springframework.org/schema/tx</a> <a href="http://www.springframework.org/schema/tx/spring-tx.xsd" rel="nofollow noreferrer">http://www.springframework.org/schema/tx/spring-tx.xsd</a> <a href="http://www.springframework.org/schema/mvc" rel="nofollow noreferrer">http://www.springframework.org/schema/mvc</a> <a href="http://www.springframework.org/schema/mvc/spring-mvc.xsd" rel="nofollow noreferrer">http://www.springframework.org/schema/mvc/spring-mvc.xsd</a>"></p>
  
  <pre><code>&lt;context:component-scan base-package="net.UserList"/&gt;
  
  &lt;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
      &lt;property name="prefix" value="/WEB-INF/pages/"/&gt;
      &lt;property name="suffix" value=".jsp"/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Database Information --&gt;
  &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close"&gt;
      &lt;property name="driverClassName" value="microsoft.sqlserver.jdbc.SQLServerDriver"/&gt;
      &lt;property name="url"
                value="jdbc:sqlserver://localhost:1433/UsersDB"/&gt;
      &lt;property name="username" value=********/&gt;
      &lt;property name="password" value=**********/&gt;
  &lt;/bean&gt;
  
  &lt;!-- Hibernate 4 SessionFactory Bean definition --&gt;
  &lt;bean id="hibernate4AnnotatedSessionFactory"
        class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"/&gt;
      &lt;property name="annotatedClasses"&gt;
          &lt;list&gt;
              &lt;value&gt;net.UserList.model.User&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.SQLServer2012Dialect
              &lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;!--BookDao and BookService beans--&gt;
  &lt;bean id="userDao" class="net.UserList.dao.UserDaoImpl"&gt;
      &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;bean id="userService" class="net.UserList.service.UserServiceImpl"&gt;
      &lt;property name="userDao" ref="userDao"/&gt;
  &lt;/bean&gt;
  
  &lt;!--&lt;bean id="userService" class="net.UserList.service.UserServiceImpl"&gt;-&gt;
  &lt;!-    &lt;property name="" ref="userDao"/&gt; -&gt;
  &lt;!-&lt;/bean&gt;--&gt;
  
  &lt;!--property name="userDao" ref="userDao"/--&gt;
  
  &lt;context:component-scan base-package="net.UserList"/&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager"/&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory" ref="hibernate4AnnotatedSessionFactory"/&gt;
  &lt;/bean&gt;
  
  &lt;mvc:default-servlet-handler/&gt;
  &lt;mvc:annotation-driven/&gt;
  </code></pre>
  
  <p></p>
  
  <hr>
  
  <pre><code>My "dao-class": 
  
  package net.UserList.dao;
  
  import net.UserList.model.User;
  import org.hibernate.Session;
  import org.hibernate.SessionFactory;
  import org.slf4j.LoggerFactory;
  import org.springframework.stereotype.Repository;
  
  import java.io.Serializable;
  import java.util.List;
  import java.util.logging.Logger;
  
  @Repository
  public class UserDaoImpl implements UserDao {
  
      private static final Logger logger = (Logger) LoggerFactory.getLogger(UserDaoImpl.class);
      private SessionFactory sessionFactory;
  
      public void setSessionFactory(SessionFactory sessionFactory) {
          this.sessionFactory = sessionFactory;
      }
  
      public void addUser(User user) {
          Session session = this.sessionFactory.getCurrentSession();
          session.persist(user);
          logger.info("User add!");
      }
  
      public void editUser(User user) {
          Session session = this.sessionFactory.getCurrentSession();
          session.update(user);
          logger.info("User edit!");
      }
  
      public void removeUser(int id) {
          Session session = this.sessionFactory.getCurrentSession();
          User user = (User)session.load(User.class, new Integer(id));
          //session.update(user);
  
          if(user!=null) session.delete(user);
  
          logger.info("User removed!");
      }
  
      public User getUser(int id) {
  
          Session session = this.sessionFactory.getCurrentSession();
          User user = (User)session.load(User.class, new Integer(id));
          logger.info("User here!");
  
          return user;
      }
  
      @SuppressWarnings("unchecked")
      public List&lt;User&gt; ListUsers() {
  
          Session session = this.sessionFactory.getCurrentSession();
          List&lt;User&gt; list = session.createQuery("from User").list();
  
          for (User user:list) {
              logger.info("User: " + user);
          }
  
          return list;
      }
  }
  </code></pre>
  
  <hr>
  
  <p>My "Controller" :</p>
  
  <pre><code>package net.UserList.controller;
  
  import net.UserList.model.User;
  import net.UserList.service.UserService;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.beans.factory.annotation.Qualifier;
  import org.springframework.stereotype.Controller;
  import org.springframework.ui.Model;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.PathVariable;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  
  @Controller
  public class UserController {
  
      private UserService userService;
  
      @Autowired(required = true)
      @Qualifier(value = "userService")
      public void setUserService(UserService userService) {
          this.userService = userService;
      }
  
      @RequestMapping(value = "users",method = RequestMethod.GET)
      public String userList(Model model){
           model.addAttribute("user", new User());
           model.addAttribute("listUsers",this.userService.ListUsers());
  
           return "users";
      }
  
      @RequestMapping(value = "/users/add",method = RequestMethod.POST)
      public String addUser(@ModelAttribute("user") User user){
  
          if (user.getId() ==0 ) {
              this.userService.addUser(user);
          } else {
              this.userService.editUser(user);
          }
  
          return "redirect:/users";
      }
  
      @RequestMapping("/remove/{id}")
      public String removeUser(@PathVariable("id") int id){
          this.userService.removeUser(id);
          return "redirect:/users";
      }
  
      @RequestMapping("/edit/{id}")
      public String idtUser(@PathVariable("id") int id,Model model){
  
          model.addAttribute("user",this.userService.getUser(id));
          model.addAttribute("listUsers",this.userService.ListUsers());
  
          return "users";
  
      }
  
      @RequestMapping("/userdata/{id}")
      public String userData(@PathVariable("id") int id,Model model){
  
          model.addAttribute("user",this.userService.getUser(id));
  
          return "userdata";
      }
  }
  </code></pre>