title: Error creating bean with name 'empresasDAO': Injection of autowired dependencies failed
body: <p>I am having a problem with spring , I am a newbie using this framework with Hibernate , SQL and Maven , I am following a tutorial but when launching the app in the server I have this error message.</p>
  
  <p><strong>Spring Console</strong></p>
  
  <pre><code>Exception in thread "main" org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'empresasDAO': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: public org.hibernate.SessionFactory com.altobri.conta.dao.EmpresasDAOImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in class path resource [applicationContext.xml]: Cannot resolve reference to bean 'dataSource' while setting bean property 'dataSource'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'dataSource' defined in class path resource [applicationContext.xml]: Error setting property values; nested exception is org.springframework.beans.NotWritablePropertyException: Invalid property 'root' of bean class [org.apache.commons.dbcp.BasicDataSource]: Bean property 'root' is not writable or has an invalid setter method. Does the parameter type of the setter match the return type of the getter?
  at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:288)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1116)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:519)
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:458)
  at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:295)
  at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:223)
  at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:292)
  at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:626)
  at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:932)
  at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:479)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:139)
  at org.springframework.context.support.ClassPathXmlApplicationContext.&lt;init&gt;(ClassPathXmlApplicationContext.java:83)
  at com.altobri.conta.App.main(App.java:13)
  </code></pre>
  
  <p><strong>EmpresasDAO</strong></p>
  
  <pre><code>package com.altobri.conta.dao;
  import com.altobri.conta.model.Empresas;
  
  public interface EmpresasDAO{
  
      void persistEmpresas(Empresas empresas);
  
      Empresas findEmpresasById(int clave);
  
      void updateEmpresas(Empresas empresas);
  
      void deleteEmpresas(Empresas empresas);
  
  }
  </code></pre>
  
  <p><strong>EmpresasDAOImpl</strong></p>
  
  <pre><code>package com.altobri.conta.dao;
  import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  import com.altobri.conta.model.Empresas;
  
  @Repository("empresasDAO")
  public class EmpresasDAOImpl implements EmpresasDAO {
  
      @Autowired
      public SessionFactory sessionFactory;
  
      @Override
      public void persistEmpresas(Empresas empresas) {
          sessionFactory.getCurrentSession().persist(empresas);
      }
  
      @Override
      public Empresas findEmpresasById(int clave) {
          return (Empresas) sessionFactory.getCurrentSession().get(
                  Empresas.class, clave);
      }
  
      @Override
      public void updateEmpresas(Empresas empresas) {
          sessionFactory.getCurrentSession().update(empresas);
      }
  
      @Override
      public void deleteEmpresas(Empresas empresas) {
          sessionFactory.getCurrentSession().delete(empresas);
      }
  }
  </code></pre>
  
  <p><strong>App.java</strong></p>
  
  <pre><code>package com.altobri.conta;
  
  import org.springframework.context.ConfigurableApplicationContext;
  import org.springframework.context.support.ClassPathXmlApplicationContext;
  
  import com.altobri.conta.model.Empresas;
  import com.altobri.conta.service.EmpresasService;
  
  public class App {
  
      public static void main(String[] args) {
          System.out.println("load context");
          ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
                  "applicationContext.xml");
          Empresas em = new Empresas();
          em.setClave(123);
          em.setNombre("John");
  
          EmpresasService emService = (EmpresasService) context
                  .getBean("empresasService");
          emService.persistEmpresas(em);
          System.out.println("Updated age :"
                  + emService.findEmpresasById(123).getNombre());
  
          emService.updateEmpresas(em);
          System.out.println("Updated age :"
                  + emService.findEmpresasById(123).getClave());
          emService.deleteEmpresas(em);
          context.close();
      }
  
  }
  </code></pre>
  
  <p><strong>EmpresasService</strong></p>
  
  <pre><code>package com.altobri.conta.service;
  import com.altobri.conta.model.Empresas;
  
  public interface EmpresasService {
  
      void persistEmpresas(Empresas empresas);
  
      Empresas findEmpresasById(int clave);
  
      void updateEmpresas(Empresas empresas);
  
      void deleteEmpresas(Empresas empresas);
  }
  </code></pre>
  
  <p><strong>EmpresasServiceImpl</strong></p>
  
  <pre><code>package com.altobri.conta.service;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.altobri.conta.dao.EmpresasDAO;
  import com.altobri.conta.model.Empresas;
  
  @Service("empresasService")
  public class EmpresasServiceImpl implements EmpresasService{
  
      @Autowired
      EmpresasDAO empresasDAO;
  
      @Override
      @Transactional
      public void persistEmpresas(Empresas empresas) {
          empresasDAO.persistEmpresas(empresas);
      }
  
      @Override
      @Transactional
      public void updateEmpresas(Empresas empresas) {
          empresasDAO.updateEmpresas(empresas);
      }
  
      @Override
      @Transactional
      public Empresas findEmpresasById(int clave) {
          return empresasDAO.findEmpresasById(clave);
      }
  
      @Override
      @Transactional
      public void deleteEmpresas(Empresas empresas) {
          empresasDAO.deleteEmpresas(empresas);
      }
  
  }
  </code></pre>
  
  <p><strong>applicationContext.xml</strong></p>
  
  <pre><code>&lt;beans xmlns="http://www.springframework.org/schema/beans"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
  xmlns:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context"
  xmlns:jee="http://www.springframework.org/schema/jee" xmlns:tx="http://www.springframework.org/schema/tx"
  xmlns:task="http://www.springframework.org/schema/task"
  xsi:schemaLocation="http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.2.xsd http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.2.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.2.xsd http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee-3.2.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.2.xsd http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.2.xsd"&gt;
  
     &lt;context:component-scan base-package="com.altobri.conta.*" /&gt;
     &lt;context:component-scan base-package="com.springHibernate" /&gt;
     &lt;context:annotation-config /&gt;
  
     &lt;tx:annotation-driven/&gt;
  
     &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"destroymethod="close"&gt;
  &lt;property name="driverClassName" value="com.mysql.jdbc.Driver" /&gt;
  &lt;property name="url" value="jdbc:mysql://localhost:3306/empresas" /&gt;
  &lt;property name="root" value="root" /&gt;
  &lt;property name="password" value="" /&gt;
  &lt;/bean&gt;
  
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
      &lt;property name="dataSource" ref="dataSource"&gt;&lt;/property&gt;
       &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.altobri.conta.model.Empresas&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.MySQL5Dialect&lt;/prop&gt;
          &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
        &lt;/props&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager" 
  p:Factory-ref="sessionFactory"&gt;
  &lt;/bean&gt;
  &lt;/beans&gt;
  </code></pre>