title: Spring could not autowire field, No matching bean of type
body: <p>I try to implement using Spring 3.1.0.RELEASE + Hibernate to make RESTful web service followed this guy's project <a href="https://github.com/eugenp/REST" rel="nofollow">https://github.com/eugenp/REST</a></p>
  
  <p>when I run my project is contain error like this.</p>
  
  <pre><code>SEVERE: Context initialization failed
  *.BeanCreationException: Error creating bean with name 'userServiceController': Injection of autowired dependencies failed;
  *.BeanCreationException: Error creating bean with name 'defaultUserService': Injection of autowired dependencies failed;
  *.BeanCreationException: Could not autowire field: private com.cloudlb.dao.UserDAO com.cloudlb.service.DefaultUserService.userDao;
  *.NoSuchBeanDefinitionException: No matching bean of type [com.cloudlb.dao.UserDAO]
  </code></pre>
  
  <p>This is my configuration: (persistence.properties)</p>
  
  <p>ApplicationConfig:</p>
  
  <pre><code>@Configuration
  @ComponentScan(basePackages = "com.cloudlb", excludeFilters = { @ComponentScan.Filter(Configuration.class)})
  public class ApplicationConfig {
  
      @Bean
      public static PropertyPlaceholderConfigurer properties() {
          final PropertyPlaceholderConfigurer ppc = new PropertyPlaceholderConfigurer();
          final Resource[] resources = new ClassPathResource[]{new ClassPathResource("persistence.properties"), new ClassPathResource("restful.properties")};
          ppc.setLocations(resources);
          ppc.setIgnoreUnresolvablePlaceholders(true);
          return ppc;
      }
  </code></pre>
  
  <p>In PersistenceHibernateConfig contain like this:</p>
  
  <pre><code>@Profile("hibernate")
  @EnableTransactionManagement
  public class PersistenceHibernateConfig { ...
  
      @Bean
      public LocalSessionFactoryBean alertsSessionFactoryBean() { ...
  
      @Bean
      public DataSource restDataSource() { ...
  
      @Bean
      public HibernateTransactionManager transactionManager() { ...
  </code></pre>
  
  <p>WebConfig:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class WebConfig { ... }
  </code></pre>
  
  <p>So, it start get an error in autowired from here:</p>
  
  <p>UserServiceController:</p>
  
  <pre><code>@Controller
  public class UserServiceController {
  
      @Autowired
      private UserService userService;
  </code></pre>
  
  <p>UserService which is implemented by DefaultUserService:</p>
  
  <pre><code>@Service
  @Transactional(propagation = Propagation.REQUIRED)
  public class DefaultUserService implements UserService {
  
      @Autowired
      private UserDAO userDao;
  </code></pre>
  
  <p>UserDAO:</p>
  
  <pre><code>public interface UserDAO extends GenericDAO&lt;User&gt; {  ... }
  </code></pre>
  
  <p>UserHibernateDAO:</p>
  
  <pre><code>@Profile("hibernate")
  public class UserHibernateDAO extends GenericHibernateDAO&lt;User&gt; implements UserDAO{ ... }
  </code></pre>
  
  <p>GenericHibernateDAO:</p>
  
  <pre><code>@Profile("hibernate")
  @Scope(BeanDefinition.SCOPE_PROTOTYPE)
  public class GenericHibernateDAO&lt;T extends Serializable&gt; extends AbstractHibernateDAO&lt;T&gt; implements GenericDAO&lt;T&gt; { ... }
  </code></pre>
  
  <p>And last one AbstractHibernateDAO:</p>
  
  <pre><code>@Transactional( propagation = Propagation.SUPPORTS )
  public abstract class AbstractHibernateDAO&lt;T extends Serializable&gt; implements DAO&lt;T&gt; {
  
      private Class&lt;T&gt; clazz;
  
      @Autowired
      private SessionFactory sessionFactory;
  
      public AbstractHibernateDAO() {
          super();
      }
  
      public final void setClazz(final Class&lt;T&gt; clazz) {
          this.clazz = clazz;
      }
  
      @Override
      @Transactional( readOnly = true )
      public T findById(String id) {
          return (T) this.getCurrentSession().get(this.clazz, id);
      }
  
      protected Session getCurrentSession() {
          return this.sessionFactory.getCurrentSession();
      }
  }
  </code></pre>
  
  <p>I thought it could find UserHibernateDAO. May be I missing something here. So, hope someone know how to fix it. I struck at this problem for 2 day.</p>
  
  <p>I guess there could be a problem in SessionFactory too. Because I start to fix that thing and this came up.</p>
  
  <p>Thank you in advance.</p>