2

I'm developing an application which will get data from Twitter. First I created an application.properties that contains the consumer ID and secret. Second I created a controller and injected Twitter and ConnectionRepository. I did everything as explained in the Spring Getting Started Guide

But I'm getting the error below.

@RestController
@RequestMapping("/api")
public class MarketDataResource {

    private Twitter twitter;
    private ConnectionRepository connectionRepository;

    @Inject    
    public MarketDataResource(Twitter twitter, ConnectionRepository connectionRepository) {
        this.twitter = twitter;
        this.connectionRepository = connectionRepository;
    }


    @GetMapping("/market/data")
    public String searchTweet (Model model) {
        if (connectionRepository.findPrimaryConnection(Twitter.class) == null) {
            return "redirect:/connect/twitter";
        }

        model.addAttribute(twitter.userOperations().getUserProfile());
        CursoredList<TwitterProfile> friends = twitter.friendOperations().getFriends();
        model.addAttribute("friends", friends);
        return "hello";
    }

}`

Error stack:

Parameter 0 of constructor in fr.softeam.group.stockpicking.web.rest.data.MarketDataResource required a bean of type 'org.springframework.social.twitter.api.Twitter' that could not be found. Action: Consider defining a bean of type 'org.springframework.social.twitter.api.Twitter' in your configuration.

chrylis -cautiouslyoptimistic-
  • 75,269
  • 21
  • 115
  • 152
  • So far your code is looking pretty good, including constructor injection. As the error message says, there's no `Twitter` bean available in your configuration. Since you set up `application.properties`, the next step is to start your program with `--debug`; it will explain each autoconfigured bean that isn't turned on. Most likely, you're missing a Spring Boot Starter dependency for Twitter. – chrylis -cautiouslyoptimistic- Aug 22 '18 at 23:42
  • @chrylis thanks for your response. I will add Spring Boot Starter dependency for Twitter. But In the example provided in https://spring.io/guides/gs/accessing-twitter/ there is no dependency for that. Is there something else I missed? thanks – Hamidou Balde Aug 22 '18 at 23:51
  • I haven't worked with the Twitter API in a long time, so I don't know for sure. Look at the autoconfiguration report in the debug log. It will be long, but look for any class with "Twitter" in its name. – chrylis -cautiouslyoptimistic- Aug 22 '18 at 23:52
  • @chrylis not seen Twitter class. I'm so confused. I added spring boot starter dependency for twitter but still facing same error. – Hamidou Balde Aug 23 '18 at 00:13
  • Please post your `pom.xml` file. Your class _compiled_, so you have the Twitter classes available, but apparently not the configuration somehow. – chrylis -cautiouslyoptimistic- Aug 23 '18 at 01:22
  • Can you check and see whether you have the class `TwitterAutoConfiguration` available in your project? – chrylis -cautiouslyoptimistic- Aug 23 '18 at 01:25

0 Answers0