Spring Social 3.0.0.M1 中的 class org.springframework.social.connect.ConnectionRepository 发生了什么?

What has happened with the class org.springframework.social.connect.ConnectionRepository in Spring Social 3.0.0.M1?

我是 Spring 框架的初学者,想尝试 Spring Social 来制作一个从 Facebook 检索数据的简单 Web 应用程序。为此,我关注了 Spring Socials 官方“入门指南”,名为“访问 Facebook 数据”。

我遇到的第一个问题是Spring社会版2.0.3.RELEASE,好像是[=62]的最新官方版本=] 社交,不支持 facebook 的 2.8 版 API(因此出现以下错误:“(#12) v2.8 及更高版本不推荐使用生物字段”)。因为我昨天在 developers.facebook.com 创建了 Facebook 应用程序,所以我似乎无法访问以前的 API 版本。

我用 google 搜索了一个解决方案,发现版本 3.0.0.M1 似乎在 maven 存储库中可用,应该可以解决这个问题问题。但是,当我更改 .pom 文件中的配置以使用此版本时,编译器再也找不到 class ConnectionRepository 了。实际上整个包裹 org.springframework.social.connect 似乎都不见了。

我从指南 (https://spring.io/guides/gs/accessing-facebook/) 复制的代码如下所示:

import org.springframework.social.connect.ConnectionRepository;
import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Post;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/")
public class HelloController {

    private Facebook facebook;
    private ConnectionRepository connectionRepository;

    public HelloController(Facebook facebook, ConnectionRepository connectionRepository) {
        this.facebook = facebook;
        this.connectionRepository = connectionRepository;
    }

    @GetMapping
    public String helloFacebook(Model model) {
        if (connectionRepository.findPrimaryConnection(Facebook.class) == null) {
            return "redirect:/connect/facebook";
        }

        model.addAttribute("facebookProfile", facebook.userOperations().getUserProfile());
        PagedList<Post> feed = facebook.feedOperations().getFeed();
        model.addAttribute("feed", feed);
        return "hello";
    }

}

ConnectionRepository 是否已弃用并且现在已删除?如果是这样的话,我应该用别的东西代替吗?还是我遗漏了什么?

只是删除对 ConnectionRepository 的所有引用,在启动应用程序时会出现以下错误:

org.springframework.beans.factory.BeanCreationException:创建名称为 'helloController' 的 bean 时出错:从 Class 解析 bean Class [hello.HelloController] 上声明的构造函数]加载程序[sun.misc.Launcher$AppClassLoader@73d16e93] 失败;嵌套异常是 java.lang.NoClassDefFoundError: org/springframework/social/ApiBinding

在这种情况下,代码如下所示:

package hello;

import org.springframework.social.facebook.api.Facebook;
import org.springframework.social.facebook.api.PagedList;
import org.springframework.social.facebook.api.Post;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/")
public class HelloController {

    private Facebook facebook;

    public HelloController(Facebook facebook) {
        this.facebook = facebook;

    }

    @GetMapping
    public String helloFacebook(Model model) {


        model.addAttribute("facebookProfile", facebook.userOperations().getUserProfile());
        PagedList<Post> feed = facebook.feedOperations().getFeed();
        model.addAttribute("feed", feed);
        return "hello";
    }

}

在查看了神器 spring-social-facebook 的 git 源代码历史后,我从 GitHub 获得了它,我无法根本找不到 ConnectionRepository 的任何踪迹。

在 mvnrepository.com 查看后,我意识到当使用版本 2.0.3.RELEASE 的工件 spring-social-facebook 作为依赖项比使用版本 3.0.0.M1 作为依赖项时更多 jar-files 由 Maven 下载。在丢失的 jar-filer 中,有两个我需要启动我的应用程序的工件和 运行。他们是 spring-social-corespring-social-config.

最后我在spring-social-corejar-file.

中找到了ConnectionRepository

所以我最终需要做的是更改指南中原始 pom-file 中的依赖项,如下所示:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-facebook</artifactId>
    </dependency>
</dependencies>

至:

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-thymeleaf</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-facebook</artifactId>
        <version>3.0.0.M1</version>
        </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-core</artifactId>
        <version>2.0.0.M2</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-config</artifactId>
        <version>2.0.0.M2</version>
    </dependency>
</dependencies>

这些更改使我能够启动应用程序并检索一些 facebook 数据。