title: Autowired error spring
body: <p>I am new to spring. Previous I have used to configure the auto wiring using spring- context xml.
  Now my project we are using annotation directly to inject the bean.</p>
  
  <p>I am getting following exception when I try to auto wire Mongo repository.</p>
  
  <p>Below is the sample code.</p>
  
  <p><strong>StagingDocumentServiceImpl:</strong></p>
  
  <pre><code>@Service
  public class StagingDocumentServiceImpl implements StagingDocumentService {
  
  private static final Logger logger = Logger.getLogger(StagingDocumentServiceImpl.class);
  @Autowired
  private StagingDocumentRepository stagingDocumentRepository;
  
  /**
   * 
   */
  @Override
  @Transactional(readOnly = false)
  public List&lt;String&gt; saveRawData(Tuple twitter) {
  
      List&lt;String&gt; tweetIDs = new ArrayList&lt;String&gt;();
      System.out.println("Twitter information get passed.." + twitter);
      Status tweets = (Status) twitter
              .getValueByField(TopologyConstants.TWEETSPOUT_OUT_FIELD);
      //try{
      CIPPayload twitterPayload = DataCaptureTwitterUtil
              .getrawJSONPayloadFromTwitterResponse(tweets);
      String parentID = null;
      System.out.println("twitterPayload"+twitterPayload);
      String tweetParentId = twitterPayload.getContent().getParentContentId();
      /*if (StringUtils.isNotBlank(tweetParentId)) {
          DBObject queryObject = new BasicDBObject();
          queryObject.put("content.id", tweetParentId);
          DBObject resultedData = stagingDocumentRepository.fi
          if (resultedData == null) {
              parentID = getOriginalTweet(tweetParentId);
              tweetIDs.add(parentID);
          }
  
      }*/
  
      Test test = stagingDocumentRepository.save(twitterPayload);
  
      System.out.println("test--&gt;"+test);
  
  
      return tweetIDs;
  }
  </code></pre>
  
  <p><strong>StagingDocumentRepository:</strong></p>
  
  <pre><code> public interface StagingDocumentRepository extends
    MongoRepository&lt;CIPPayload, Serializable&gt; {
  
   }
  </code></pre>
  
  <p>The problem is  I do know how to configure using <strong>@bean</strong> annotation.</p>
  
  <p>I have tried to configure like below.</p>
  
  <p>After all below answer I have changed the configuartion as below.</p>
  
  <p>But changing this also does not work.</p>
  
  <pre><code>@Configuration
  public class AppConfig {
      @Bean
      @Bean
      public StagingDocumentRepository stagingDocumentRepository(){
          return new StagingDocumentRepository() {
  
              @Override
              public &lt;S extends CIPPayload&gt; S save(S entity) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public CIPPayload findOne(Serializable id) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public Iterable&lt;CIPPayload&gt; findAll(Iterable&lt;Serializable&gt; ids) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public boolean exists(Serializable id) {
                  // TODO Auto-generated method stub
                  return false;
              }
  
              @Override
              public void deleteAll() {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void delete(Iterable&lt;? extends CIPPayload&gt; entities) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void delete(CIPPayload entity) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public void delete(Serializable id) {
                  // TODO Auto-generated method stub
  
              }
  
              @Override
              public long count() {
                  // TODO Auto-generated method stub
                  return 0;
              }
  
              @Override
              public Page&lt;CIPPayload&gt; findAll(Pageable pageable) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public &lt;S extends CIPPayload&gt; List&lt;S&gt; save(Iterable&lt;S&gt; entites) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public List&lt;CIPPayload&gt; findAll(Sort sort) {
                  // TODO Auto-generated method stub
                  return null;
              }
  
              @Override
              public List&lt;CIPPayload&gt; findAll() {
                  // TODO Auto-generated method stub
                  return null;
              }
          };
  }
  </code></pre>
  
  <p><strong>Output:</strong></p>
  
  <pre><code>org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'stagingDocumentServiceImpl': Injection of autowired dependencies failed; nested exception is org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.biomorf.cip.datacapture.repository.payload.StagingDocumentRepository com.biomorf.cip.datacapture.processing.serviceImpl.StagingDocumentServiceImpl.stagingDocumentRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.biomorf.cip.datacapture.repository.payload.StagingDocumentRepository] 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)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:292) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1185) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:537) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:475) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:302) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:228) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:298) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:703) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:760) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:482) ~[spring-context-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:691) [spring-boot-1.1.4.RELEASE.jar:1.1.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:320) [spring-boot-1.1.4.RELEASE.jar:1.1.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:952) [spring-boot-1.1.4.RELEASE.jar:1.1.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:941) [spring-boot-1.1.4.RELEASE.jar:1.1.4.RELEASE]
      at com.biomorf.cip.datacapture.Application.main(Application.java:32) [classes/:na]
         Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private com.biomorf.cip.datacapture.repository.payload.StagingDocumentRepository com.biomorf.cip.datacapture.processing.serviceImpl.StagingDocumentServiceImpl.stagingDocumentRepository; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.biomorf.cip.datacapture.repository.payload.StagingDocumentRepository] 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)}
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:508) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:87) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:289) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      ... 15 common frames omitted
         Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [com.biomorf.cip.datacapture.repository.payload.StagingDocumentRepository] 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)}
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.raiseNoSuchBeanDefinitionException(DefaultListableBeanFactory.java:1103) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:963) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
      at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480) ~[spring-beans-4.0.6.RELEASE.jar:4.0.6.RELEASE]
  </code></pre>