Spring Social LinkedIn:找不到的“ org.springframework.social.linkedin.api.LinkedIn”

时间:2018-10-17 22:13:28

标签: spring-boot spring-social spring-social-linkedin

我正在尝试使用Spring Boot创建一个Spring Social应用程序,而Im面临启动它的问题。我已经遍历了Spring社交文档和Spring Social示例项目,它们在网上搜索。我尝试过的任何方法都没有用,如果有人可以在这里帮助我,我在徘徊。

LinkedInController

    package com.example.demo;

    import org.springframework.social.connect.ConnectionRepository;
    import org.springframework.social.linkedin.api.LinkedIn;
    import org.springframework.social.linkedin.api.ProfileOperations;
    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("/linkedin")
    public class LinkedInController {

private static final String LINKEDIN_DISPLAY = "linkedin";
private static final String LINKEDIN_REDIRECT = "redirect:/connect/linkedin";

private LinkedIn linkedIn;
private ConnectionRepository connectionRepository;

public LinkedInController(LinkedIn linkedIn, ConnectionRepository connectionRepository) {
    this.linkedIn = linkedIn;

    this.connectionRepository = connectionRepository;
}

@GetMapping
public String helloLinkedIn(Model model) {
    if (connectionRepository.findPrimaryConnection(LinkedIn.class) == null) {
        return LINKEDIN_REDIRECT;

    }
    ProfileOperations user = linkedIn.profileOperations();
    System.out.println(user);
    model.addAttribute("linkedInProfile",linkedIn.profileOperations().getUserProfileFull());



    return LINKEDIN_DISPLAY;
}

}

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0     http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.example</groupId>
<artifactId>HCLinkedIn</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>

<name>HCLinkedIn</name>
<description>Demo project for Spring Boot</description>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.0.6.RELEASE</version>
    <relativePath /> <!-- lookup parent from repository -->
</parent>

<properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.8</java.version>
    <start-class>com.example.demo.HcLinkedInApplication</start-class>
</properties>

<dependencies>
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-linkedin</artifactId>
        <version>1.0.2.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-core</artifactId>
        <version>1.1.6.RELEASE</version>
    </dependency>
    <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-config</artifactId>
        <version>1.1.6.RELEASE</version>
    </dependency>
    <!-- <dependency>
        <groupId>org.springframework.social</groupId>
        <artifactId>spring-social-security</artifactId>
        <version>1.1.6.RELEASE</version>
    </dependency> -->

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>
<repositories>
    <repository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </repository>
</repositories>
<pluginRepositories>
    <pluginRepository>
        <id>spring-snapshots</id>
        <name>Spring Snapshots</name>
        <url>https://repo.spring.io/libs-milestone</url>
        <snapshots>
            <enabled>false</enabled>
        </snapshots>
    </pluginRepository>
</pluginRepositories>

application.properties

spring.social.linkedin.app-id=<<client-key>>
spring.social.linkedin.app-secret=<<client-secret>>

1 个答案:

答案 0 :(得分:0)

我遇到了同样的问题,结果我忘了添加OAuth2.0重定向网址。

在linkedin上并在 OAuth 2.0

标题下登录开发人员的帐户

将有一个名为授权重定向URL:

的重定向URL输入字段。

添加重定向url..say,例如您正在使用本地主机进行测试,将 http://localhost:8080/connect/linkedin

用端口替换8080,用/ connect / linkedin替换用于访问授权的任何内容。

此外,如果您未指定。.将linkedinConnect.html和linkedinConnected.html添加到模板/连接