gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 11:47:00 28 4
gpt4 key购买 nike

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

我遇到的第一个问题是Spring Social版本2.0.3.RELEASE,这似乎是Spring Social的最新官方版本,不支持2.8版本的facebook API(并且因此,出现以下错误:“(#12) bio 字段在 v2.8 及更高版本中已弃用”)。由于我昨天在 Developers.facebook.com 上创建了 Facebook 应用程序,因此我似乎无法访问以前的 API 版本。

我用google搜索了解决方案,发现maven存储库中似乎有版本3.0.0.M1,这应该可以解决这个问题。但是,当我更改 .pom 文件中的配置以使用此版本时,编译器再也找不到类 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时出错:从ClassLoader [sun.misc.Launcher$AppClassLoader@73d16e93]解析bean类[hello.HelloController]上声明的构造函数失败的;嵌套异常是 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";
}

}

最佳答案

查看从 GitHub 获取的神器 spring-social-facebook 源代码的 git 历史记录后,我找不到任何 ConnectionRepository 的踪迹> 完全没有。

在 mvnrepository.com 上查看后,我意识到当使用工件 spring-social-facebook 的版本 2.0.3.RELEASE 作为依赖项时,更多jar 文件由 Maven 下载,而不是使用版本 3.0.0.M1 作为依赖项时的情况。缺少的 jar 文件管理器中有两个工件,我需要它们来启动并运行我的应用程序。它们是 spring-social-corespring-social-config

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

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

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

关于spring - Spring Social 3.0.0.M1 中的 org.springframework.social.connect.ConnectionRepository 类发生了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42168663/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com