title: Spring+HibernateDAO DAO bean not found
body: <p>I've faced the issue that I cannot defeat.</p>
  
  <p>I have a Controller:</p>
  
  <pre><code>@Controller
  @RequestMapping(value = "/admin")
  public class AdminController {
  
  @Autowired
  private HibernateUserDAO hibernateUserDAO;
  
  //Here is some further code
  </code></pre>
  
  <p>Here is my snippet of HibernateDAO:</p>
  
  <pre><code>@Repository
  @Transactional
  public class HibernateUserDAO implements UserDAO {
  
  @Autowired
  private SessionFactory sessionFactory;
  
  private Session getCurrentSession(){
      return sessionFactory.getCurrentSession();
  }
  
  @Override
  
  public void addUser(User user) {
      getCurrentSession().save(user);
  }
  </code></pre>
  
  <p>Here is my spring config file:</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:context="http://www.springframework.org/schema/context"
         xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:tx="http://www.springframework.org/schema/tx"
         xsi:schemaLocation="http://www.springframework.org/schema/beans
         http://www.springframework.org/schema/beans/spring-beans.xsd
         http://www.springframework.org/schema/context
         http://www.springframework.org/schema/context/spring-context.xsd
         http://www.springframework.org/schema/mvc
         http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd"&gt;
  
         &lt;context:component-scan base-package="ua.macko"/&gt;
         &lt;mvc:annotation-driven/&gt;
         &lt;mvc:resources mapping="/resources/**" location="/resources"/&gt;
         &lt;tx:annotation-driven/&gt;
  
         &lt;bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver"&gt;
                &lt;property name="prefix" value="/WEB-INF/jsps/"/&gt;
                &lt;property name="suffix" value=".jsp"/&gt;
         &lt;/bean&gt;
  
         &lt;bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"&gt;
                &lt;property name="driverClassName" value="com.mysql.jdbc.Driver"/&gt;
                &lt;property name="url" value="jdbc:mysql://localhost:3306/blog"/&gt;
                &lt;property name="username" value="****"/&gt;
                &lt;property name="password" value="****"/&gt;
                &lt;property name="initialSize" value="5"/&gt;
                &lt;property name="maxActive" value="10"/&gt;
         &lt;/bean&gt;
  
  
  
  
  
  
         &lt;bean id="conversionService" class="org.springframework.format.support.FormattingConversionServiceFactoryBean"&gt;
                &lt;property name="formatters"&gt;
                       &lt;set&gt;
                              &lt;ref bean="userFormatter"/&gt;
                       &lt;/set&gt;
                &lt;/property&gt;
  
         &lt;/bean&gt;
  
         &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"&gt;
                &lt;property name="annotatedClasses"&gt;
                       &lt;list&gt;
                              &lt;value&gt;ua.macko.entity.User&lt;/value&gt;
                       &lt;/list&gt;
                &lt;/property&gt;
                &lt;property name="dataSource" ref="dataSource"/&gt;
                &lt;property name="hibernateProperties"&gt;
                       &lt;props&gt;
                              &lt;prop key="format_sql"&gt;true&lt;/prop&gt;
                              &lt;prop key="show_sql"&gt;true&lt;/prop&gt;
                              &lt;prop key="dialect"&gt;org.hibernate.dialect.MySQL5Dialect&lt;/prop&gt;
                       &lt;/props&gt;
                &lt;/property&gt;
         &lt;/bean&gt;
  
         &lt;bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
                &lt;property name="sessionFactory" ref="sessionFactory"/&gt;
         &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The problem is I've got the error:</p>
  
  <pre><code>Could not autowire field: private ua.macko.dao.impl.hibernate.HibernateUserDAO ua.macko.controller.AdminController.hibernateUserDAO; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [ua.macko.dao.impl.hibernate.HibernateUserDAO] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
  </code></pre>
  
  <p>If I remove tx:annotation-driven from spring configuration, I can launch the project, but when I try to perform addUser() Method then I've got an error:</p>
  
  <pre><code>org.hibernate.HibernateException: No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here
  </code></pre>
  
  <p>How can I solve this? How is tx:annotation:driven can influence the bean autowiring?</p>