我是Spring Framework的初學者,想試試Spring Social來製作一個簡單的Web應用程序,它從Facebook中檢索數據。爲此我遵循Spring Socials官方「入門指南」,名爲「訪問Facebook數據」。Spring Social 3.0.0.M1中的org.springframework.social.connect.ConnectionRepository類發生了什麼?
我遇到的第一個問題是,Spring社交版本2.0.3.RELEASE,它似乎是Spring Social的最新正式版本,不支持facebook API的2.8版本(因此給了我以下錯誤:「(#12)生物字段已被棄用,版本v2.8及更高版本」)。正如我昨天在developers.facebook.com上創建了Facebook應用程序,似乎我無法訪問以前的API版本。
我搜索谷歌的解決方案,並發現版本3.0.0.M1似乎是可用的Maven存儲庫,這是應該解決這個問題。但是當我在我的.pom文件中更改配置以使用此版本時,編譯器無法再找到類ConnectionRepository。其實整個包org.springframework.social.connect似乎缺少。
的代碼,這是我從導向複製(https://spring.io/guides/gs/accessing-facebook/)看起來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棄用,現在去掉?如果是這種情況,我應該使用其他的東西嗎?或者我錯過了什麼?
僅僅取消對ConnectionRepository所有引用給了我下面的錯誤,而不是啓動應用程序時:對豆決議宣佈的構造函數:
org.springframework.beans.factory.BeanCreationException:錯誤創建豆名爲「的HelloController」 ClassLoader [[email protected]]中的類[hello.HelloController]失敗;嵌套的例外是java.lang.NoClassDefFoundError:組織/ springframework的/社會/ 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";
}
}
非常具有啓發性。我發現3.0.0.M1是在春節里程碑庫,所以不得不將它添加到我的POM第一: '<庫> 春里程碑庫 http://repo.spring.io /里程碑/ 存儲庫> –
acdhirr