title: No matching bean of type [org.springframework.social.twitter.api.Twitter] found for dependency
body: <p>I'm using Spring Social to connect to Twitter.
  The connect part works okay, but when I try to get the friends list, I get the following error:</p>
  
  <pre><code>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No matching bean of type [org.springframework.social.twitter.api.Twitter] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}
  </code></pre>
  
  <p>My Controller class:</p>
  
  <pre><code>@Controller
  @RequestMapping("/social")
  public class SocialController {
  
      private final Twitter twitter;
  
      @Inject
      public SocialController(Twitter twitter) {
          this.twitter = twitter;
      }
  
      @RequestMapping(value="/twitter/friends", method=RequestMethod.GET)
  public String friends(Model model) {
      model.addAttribute("profiles", twitter.friendOperations().getFriends());
      return "twitter/friends";
  }
  }
  </code></pre>
  
  <p>My XML config is as follows: (only relevant part shown)</p>
  
  <pre><code>&lt;!-- Spring Social --&gt;
      &lt;bean id="connectionFactoryLocator"
          class="org.springframework.social.connect.support.ConnectionFactoryRegistry"&gt;
          &lt;property name="connectionFactories"&gt;
              &lt;list&gt;
                  &lt;bean
                      class="org.springframework.social.twitter.connect.TwitterConnectionFactory"&gt;
                      &lt;constructor-arg value="${twitter.consumerKey}" /&gt;
                      &lt;constructor-arg value="${twitter.consumerSecret}" /&gt;
                  &lt;/bean&gt;
                  &lt;bean
                      class="org.springframework.social.facebook.connect.FacebookConnectionFactory"&gt;
                      &lt;constructor-arg value="${facebook.clientId}" /&gt;
                      &lt;constructor-arg value="${facebook.clientSecret}" /&gt;
                  &lt;/bean&gt;
              &lt;/list&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;bean id="textEncryptor" class="org.springframework.security.crypto.encrypt.Encryptors"
          factory-method="noOpText" /&gt;
  
      &lt;bean id="usersConnectionRepository"
          class="org.springframework.social.connect.jdbc.JdbcUsersConnectionRepository"&gt;
          &lt;constructor-arg ref="jpaDataSource" /&gt;
          &lt;constructor-arg ref="connectionFactoryLocator" /&gt;
          &lt;constructor-arg ref="textEncryptor" /&gt;
      &lt;/bean&gt;
  
      &lt;bean id="connectionRepository" factory-method="createConnectionRepository"
          factory-bean="usersConnectionRepository" scope="request"&gt;
          &lt;constructor-arg value="#{request.userPrincipal.name}" /&gt;
          &lt;aop:scoped-proxy proxy-target-class="false" /&gt;
      &lt;/bean&gt;
  
      &lt;bean class="org.springframework.social.connect.web.ConnectController"&gt;
          &lt;!-- relies on by-type autowiring for the constructor-args --&gt;
          &lt;property name="applicationUrl" value="${application.url}" /&gt;
      &lt;/bean&gt;
      &lt;!-- Spring Social --&gt;
  </code></pre>
  
  <p>Please guide. I'll be very thankful.</p>
  
  <h2>EDIT</h2>
  
  <p>I think I forgot to add </p>
  
  <pre><code>@Bean
      @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)   
      public Twitter twitter() {
          Connection&lt;Twitter&gt; twitter = connectionRepository().findPrimaryConnection(Twitter.class);
          return twitter != null ? twitter.getApi() : new TwitterTemplate();
      }
  </code></pre>
  
  <p>to the XML file. Any idea how it would be represented in the XML context. I'm new to Annotation based config &amp; hence using xml based ones. Please help.</p>
  
  <h2>EDIT 2</h2>
  
  <p>I settled for a workaround. Decided to use both Annotation based config and XML based config together.
  Just adding the thing I did for everyone:</p>
  
  <p>I added a config:</p>
  
  <pre><code>public class SocialApiConfig {
      @Bean
      @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)   
      public Facebook facebook(ConnectionRepository connectionRepository) {
          Connection&lt;Facebook&gt; facebook = connectionRepository.findPrimaryConnection(Facebook.class);
          return facebook != null ? facebook.getApi() : new FacebookTemplate();
      }
  
      @Bean
      @Scope(value="request", proxyMode=ScopedProxyMode.INTERFACES)   
      public Twitter twitter(ConnectionRepository connectionRepository) {
          Connection&lt;Twitter&gt; twitter = connectionRepository.findPrimaryConnection(Twitter.class);
          return twitter != null ? twitter.getApi() : new TwitterTemplate();
      }
  }
  </code></pre>
  
  <p>Then included this in my XML based config</p>
  
  <pre><code>&lt;bean class="com.joinups.config.SocialApiConfig" /&gt;
  </code></pre>
  
  <p>Thanks to everyone for guiding me get the correct answer! Thanks a lot. You guys rock!</p>