Spring Social 3.0.0.M1中的org.springframework.social.connect.ConnectionRepository类发生了什么? [英] What has happened with the class org.springframework.social.connect.ConnectionRepository in Spring Social 3.0.0.M1?

本文介绍了Spring Social 3.0.0.M1中的org.springframework.social.connect.ConnectionRepository类发生了什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Spring框架的初学者,想尝试Spring Social来制作一个简单的Web应用程序,该应用程序从Facebook检索数据.为此,我遵循了Spring Socials官方的"入门指南",即"访问Facebook数据".

I am a beginner with the Spring Framework and wanted to try out Spring Social to make a simple web application which retrieves data from Facebook. For this I followed Spring Socials official "Getting started guide" called "Accessing Facebook Data".

我遇到的第一个问题是Spring Social版本 2.0.3.RELEASE (似乎是Spring Social的最新正式版本)不支持2.8版的Facebook API(并且因此会出现以下错误:对于版本v2.8及更高版本,不推荐使用(#12)bio field ").昨天我在developers.facebook.com上创建了Facebook应用程序,看来我无权访问以前的API版本.

The first problem I encountered was that the Spring Social version 2.0.3.RELEASE, which seems to be the latest official version of Spring Social, does not support version 2.8 of the facebook API (and therefore gives me the following error: "(#12) bio field is deprecated for versions v2.8 and higher"). As I have created the Facebook app at developers.facebook.com yesterday it seems I don't have access to the previous API versions.

我在Google上搜索了一个解决方案,发现在Maven存储库中似乎可以使用版本 3.0.0.M1 ,该版本应该可以解决此问题.但是,当我将.pom文件中的配置更改为使用该版本时,编译器无法再找到 ConnectionRepository 类.实际上,整个软件包 org.springframework.social.connect 似乎都丢失了.

I searched with google for a solution and found that version 3.0.0.M1 seems to be available in the maven repository, which is supposed to fix this problem. But when I changed the configuration in my .pom-file to use this version instead the compiler can't find the class ConnectionRepository anymore. Actually the whole package org.springframework.social.connect seems to be missing.

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

The code, which I copied from the guide (https://spring.io/guides/gs/accessing-facebook/) looks as followig:

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,现在将其删除了?如果是这种情况,我应该改用其他东西吗?还是我错过了什么?

Was ConnectionRepository deprecated and now removed? If that is the case should I use something else instead? Or am I missing something?

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

Just removing all references to ConnectionRepository gives me following error instead when starting the application:

org.springframework.beans.factory.BeanCreationException:创建名称为'helloController'的bean时出错:来自ClassLoader [sun.misc.Launcher$AppClassLoader@73d16e93]的bean类[hello.HelloController]上已声明的构造方法的解析失败的;嵌套的异常是java.lang.NoClassDefFoundError:org/springframework/social/ApiBinding

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

In this case the code looks as following:

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

}

推荐答案

查看了我从GitHub获得的工件 spring-social-facebook 的源代码的git历史之后,我根本找不到 ConnectionRepository 的任何痕迹.

After looking at the git history of the source code for the artifact spring-social-facebook, which I got from GitHub, I couldn't find any trace of ConnectionRepository at all.

在mvnrepository.com上进行检查后,我意识到,当使用工件 spring-social-facebook 的版本 2.0.3.RELEASE 作为依赖项时,它会更多与使用版本 3.0.0.M1 作为依赖项时相比,Maven所下载的jar文件要多.在缺少的jar-filer中有两个工件,我需要它们来启动和运行应用程序.它们是 spring-social-core spring-social-config .

After checking it out at mvnrepository.com I realized that when using version 2.0.3.RELEASE of the artifact spring-social-facebook as a dependency a lot more jar-files where dowloaded by Maven than it was when using version 3.0.0.M1 as a dependency. Among the missing jar-filer were two artifacts which I needed to get my application up and running. They were spring-social-core and spring-social-config.

最后,我在 spring-social-core jar文件中找到了 ConnectionRepository .

In the end I found ConnectionRepository in the spring-social-core jar-file.

最后,我要做的是更改指南中原始pom文件中的依赖项,如下所示:

So what I in the end needed to do was to change the dependencies in the original pom-file from the guide, which were the following:

<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数据.

These changes allowed me to start up the application and retrieve some facebook data.

这篇关于Spring Social 3.0.0.M1中的org.springframework.social.connect.ConnectionRepository类发生了什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆