springfacebook-graph-apispring-socialspring-social-facebookfacebook-graph-api-v2.8

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


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".

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.

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.

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

}

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

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

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'helloController': Resolution of declared constructors on bean Class [hello.HelloController] from ClassLoader [sun.misc.Launcher$AppClassLoader@73d16e93] failed; nested exception is 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";
    }

}

Solution

  • 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.

    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.

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

    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>
    

    to:

    <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>
    

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