首页 > 解决方案 > @Inject Twitter bean 一个 connectionRepository 问题

问题描述

我正在开发一个将从 Twitter 获取数据的应用程序。首先,我创建了一个application.properties包含消费者 ID 和机密的。其次,我创建了一个控制器并注入了 Twitter 和 ConnectionRepository。我按照Spring Getting Started Guide中的说明做了所有事情

但我收到以下错误。

@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";
    }

}`

错误堆栈:

fr.softeam.group.stockpicking.web.rest.data.MarketDataResource 中构造函数的参数 0 需要一个无法找到的“org.springframework.social.twitter.api.Twitter”类型的 bean。行动:考虑在你的配置中定义一个“org.springframework.social.twitter.api.Twitter”类型的bean。

标签: javaspringtwitterspring-social-twitter

解决方案


推荐阅读