title: org.springframework.beans.factory.BeanCreationException:org.springframework.beans.factory.BeanCreationException: Error creating bean
body: <p>my controller is:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Controller;
  import org.springframework.validation.BindingResult;
  import org.springframework.web.bind.annotation.ModelAttribute;
  import org.springframework.web.bind.annotation.RequestMapping;
  import org.springframework.web.bind.annotation.RequestMethod;
  import org.springframework.web.servlet.ModelAndView;
  
  import com.news.model.User;
  import com.news.service.UserService;
  
  @Controller
  @RequestMapping("/submit")
  public class UserController {
  
      @Autowired
      private UserService userService;
  
  
      @RequestMapping(method = RequestMethod.GET)
        public ModelAndView helloWorld() {
  
          return new ModelAndView("submit");
      }
  
  
      @RequestMapping(value = "/save", method = RequestMethod.POST)
      public ModelAndView saveArticle(@ModelAttribute("user") User user,  BindingResult result) {
           userService.addUser( user);
                   return new ModelAndView("redirect:/submit");
      }}
  </code></pre>
  
  <p>my dao class is:</p>
  
  <pre><code>import org.hibernate.SessionFactory;
  import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Repository;
  
  import com.news.model.User;
  
  @Repository("userDao")
  public class UserDaoImpl implements UserDao {
  
      @Autowired
      private SessionFactory sessionFactory;
  
  
      public void saveUser(User user) {
          sessionFactory.getCurrentSession().save(user);
      }
  
  
  }
  </code></pre>
  
  <p>user service is:</p>
  
  <pre><code>import com.news.model.User;
  
  public interface UserService {
  
      public void addUser(User user);
  
  }
  </code></pre>
  
  <p>userimpl is:</p>
  
  <pre><code>import org.springframework.beans.factory.annotation.Autowired;
  import org.springframework.stereotype.Service;
  import org.springframework.transaction.annotation.Propagation;
  import org.springframework.transaction.annotation.Transactional;
  
  import com.news.dao.UserDao;
  import com.news.model.User;
  
  @Service("userService")
  @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
  public class UserServiceImpl implements UserService {
  
      @Autowired
      private UserDao userDao;
  
      public UserServiceImpl() {
      }
  
      @Transactional(propagation = Propagation.REQUIRED, readOnly = false)
      public void addUser(User user) {
          userDao.saveUser(user);
      }
  
  
      }
  </code></pre>
  
  <p>I have the <strong>jdbc.properties</strong> inside <strong>WEB-INF/classes</strong></p>
  
  <p>and <strong>spring-servlet.xml</strong> is:</p>
  
  <pre><code>&lt;?xml  version="1.0" encoding="utf-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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:lang="http://www.springframework.org/schema/lang"
      xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p"
      xmlns:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
      xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schema/beans/spring-beans-4.1.xsd
                          http://www.springframework.org/schema/aop
                          http://www.springframework.org/schema/aop/spring-aop-4.1.xsd
                          http://www.springframework.org/schema/context
                          http://www.springframework.org/schema/context/spring-context-4.1.xsd
                          http://www.springframework.org/schema/jee
                          http://www.springframework.org/schema/jee/spring-jee-4.1.xsd
                          http://www.springframework.org/schema/lang
                          http://www.springframework.org/schema/lang/spring-lang-4.1.xsd
                          http://www.springframework.org/schema/mvc
                          http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd
                          http://www.springframework.org/schema/tx
                          http://www.springframework.org/schema/tx/spring-tx-4.1.xsd
                          http://www.springframework.org/schema/util
                          http://www.springframework.org/schema/util/spring-util-4.1.xsd"&gt;
  
                              &lt;tx:annotation-driven transaction-manager="hibernateTransactionManager" /&gt;
  
  
           &lt;bean id="propertyConfigurer"
                       class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"&gt;
                   &lt;property name="locations"&gt;         
                     &lt;list&gt;
                 &lt;value&gt;/WEB-INF/classes/jdbc.properties&lt;/value&gt;          
  
                   &lt;/list&gt;    
                  &lt;/property&gt;     
                   &lt;/bean&gt; 
  
  
  
      &lt;context:component-scan base-package="com.news" /&gt;
  
  
  
  
  
      &lt;mvc:resources mapping="/resources/**"  location="/resources/" /&gt; 
  
  
  
  
      &lt;bean id="tilesViewResolver"
          class="org.springframework.web.servlet.view.UrlBasedViewResolver"
          p:order="0" p:viewClass="org.springframework.web.servlet.view.tiles2.TilesView"
          p:viewNames=".*" /&gt;
  
      &lt;bean id="jstlViewResolver"
          class="org.springframework.web.servlet.view.InternalResourceViewResolver"
          p:order="1" p:viewClass="org.springframework.web.servlet.view.JstlView"
          p:prefix="/WEB-INF/jsp/" p:suffix=".jsp" /&gt;
  
  
  
  
      &lt;bean id="tilesConfigurer"
          class="org.springframework.web.servlet.view.tiles2.TilesConfigurer"&gt;
          &lt;property name="definitions"&gt;
              &lt;list&gt;
                  &lt;value&gt;/WEB-INF/tiles.xml&lt;/value&gt;
              &lt;/list&gt;
          &lt;/property&gt;
  
  
              &lt;/bean&gt; 
  
  
  
  
  
          &lt;bean id="dataSource"   class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="${database.driver}" &gt;&lt;/property&gt;
          &lt;property name="url" value="${database.url}" &gt;&lt;/property&gt;
          &lt;property name="username" value="${database.user}" &gt;&lt;/property&gt;
          &lt;property name="password" value="${database.password}" &gt;&lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="annotatedClasses"&gt;
              &lt;list&gt;
                  &lt;value&gt;com.news.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;${hibernate.dialect}&lt;/prop&gt;
                  &lt;prop key="hibernate.show_sql"&gt;${hibernate.show_sql}&lt;/prop&gt;
              &lt;/props&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="hibernateTransactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref="sessionFactory" /&gt;
      &lt;/bean&gt;
  
      &lt;/beans&gt;
  </code></pre>
  
  <p>but when I run the program I am getting error:</p>
  
  <pre><code>WARN:/TestSpring:unavailable
  
  org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userService': Injection of autowired
   dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: 
  
  Could not autowire field: private com.news.dao.UserDao com.news.service.UserServiceImpl.userDao;
  
   nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'userDao':
  
   Injection of autowired dependencies failed; 
  nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private org.hibernate.SessionFactory com.news.dao.UserDaoImpl.sessionFactory; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: Invocation of init method failed; nested exception is java.lang.NoSuchMethodError: org.hibernate.cfg.Configuration.addAnnotatedClass(Ljava/lang/Class;)Lorg/hibernate/cfg/Configuration;
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:334)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1210)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537)
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:476)
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:303)
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230)
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:299)
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:194)
  </code></pre>
  
  <p>I am using the :</p>
  
  <pre><code>**spring version 4.1.6RELEASE**
  hibernate-core-3.5.4-final,hibernate-annotations-3.5.4-final,hibernate-commons-annotations-3.3.0-final,hibernate-entitymanager-3.5.4-Final,hibernate-validator-4.0.2.GA
  </code></pre>
  
  <p>I also checked the userservice fields..there were no error also..so,where is the problem???</p>