title: No qualifying bean of type available (Spring Data)
body: <p>I'm getting this error when I try to autowire interface that extends CrudRepository. I have two hibernate xml configs for 2 databases. The full stack is</p>
  
  <blockquote>
    <p>org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'helloController': Unsatisfied dependency expressed through field 'stockService'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'com.publishing.test.stock.services.StockService' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
        org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:588)
        org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88)</p>
  </blockquote>
  
  <pre><code>&lt;hibernate-configuration&gt;
  
  &lt;session-factory&gt;
  
      &lt;!-- Database connection settings --&gt;
      &lt;property name="connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="connection.url"&gt;&lt;/property&gt;
      &lt;property name="connection.username"&gt;&lt;/property&gt;
      &lt;property name="connection.password"&gt;&lt;/property&gt;
  
      &lt;!-- JDBC connection pool (use the built-in) --&gt;
       &lt;property name="connection.pool_size"&gt;100&lt;/property&gt;
  
      &lt;!-- SQL dialect --&gt;
      &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQL95Dialect&lt;/property&gt;
  
      &lt;!-- Disable the second-level cache --&gt;
      &lt;!--&lt;property name="cache.provider_class"&gt;org.hibernate.cache.NoCacheProvider&lt;/property&gt;--&gt;
  
      &lt;!-- Enable Hibernate's automatic session context management --&gt;
      &lt;property name="current_session_context_class"&gt;thread&lt;/property&gt;
  
      &lt;!-- Echo all executed SQL to stdout --&gt;
      &lt;property name="show_sql"&gt;true&lt;/property&gt;
  
      &lt;!-- Drop the existing table and create new one --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
      &lt;property name="packagesToScan"&gt;com.publishing&lt;/property&gt;
  
      &lt;!-- Mention here all the model classes --&gt;
      &lt;mapping class="com.publishing.models.Stock"/&gt;
  
  &lt;/session-factory&gt;
  </code></pre>
  
  <p></p>
  
  <pre><code>@Controller
  public class HelloController {
  
  
  @Autowired
  private StockService stockService;
  </code></pre>
  
  <p>I have 3 lines also in Spring Config</p>
  
  <pre><code>&lt;context:component-scan base-package="com.publishing" /&gt;
  &lt;context:annotation-config /&gt;
  &lt;jpa:repositories base-package="com.publishing" /&gt;
  </code></pre>
  
  <p>Service is</p>
  
  <pre><code>@Service("StockService")
  public interface StockService extends CrudRepository&lt;Stock, Long&gt; {
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Ok, now we have edited hibernate.cfg.xml</p>
  
  <pre><code>    &lt;!-- Drop the existing table and create new one --&gt;
      &lt;property name="hbm2ddl.auto"&gt;update&lt;/property&gt;
  
      &lt;!--&lt;property name="packagesToScan"&gt;com.publishing&lt;/property&gt;--&gt;
  
      &lt;!-- Mention here all the model classes --&gt;
      &lt;mapping class="com.publishing.models.Stock"/&gt;
  </code></pre>
  
  <p>And service</p>
  
  <pre><code>@Service("stockService")
  public interface StockService extends CrudRepository&lt;Stock, Long&gt; {
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/fJrNv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fJrNv.png" alt="enter image description here"></a></p>