Spring Social ProviderSignInUtils.getConnection正在返回"错误:找不到符号"

时间:2015-09-08 14:53:57

标签: spring maven spring-mvc spring-social

我正在创建一个控制器来注册使用oauth2登录的用户,但每当我尝试使用ProviderSignInUtils.getConnection(request)获取连接时,它表示该函数不存在。

这是我的控制者:

import org.springframework.social.connect.web.ProviderSignInUtils;

    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String showRegistrationForm(WebRequest request, Model model) {

                    Connection<?> connection = ProviderSignInUtils.getConnection(request);

                    RegistrationForm registration = createRegistrationDTO(connection);
                    model.addAttribute("user", registration);

                    return "user/registrationForm";
    }

这些是maven依赖项:

<dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-config</artifactId>
            <version>1.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-core</artifactId>
            <version>1.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-security</artifactId>
            <version>1.1.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.social</groupId>
            <artifactId>spring-social-web</artifactId>
            <version>1.1.2.RELEASE</version>
        </dependency>

1 个答案:

答案 0 :(得分:4)

在Spring Social 1.1.2中删除了

ProviderSignInUtils.getConnection,但是文档没有更新以反映这一点。 github处的示例代码显示了

@Inject
public SignupController(AccountRepository accountRepository, 
                        ConnectionFactoryLocator connectionFactoryLocator,
                        UsersConnectionRepository connectionRepository) {
    this.accountRepository = accountRepository;
    this.providerSignInUtils = new ProviderSignInUtils(connectionFactoryLocator, connectionRepository);
}

@RequestMapping(value="/signup", method=RequestMethod.GET)
public SignupForm signupForm(WebRequest request) {
    Connection<?> connection = providerSignInUtils.getConnectionFromSession(request);
    if (connection != null) {
        request.setAttribute("message", new Message(MessageType.INFO, "Your " + StringUtils.capitalize(connection.getKey().getProviderId()) + " account is not associated with a Spring Social Showcase account. If you're new, please sign up."), WebRequest.SCOPE_REQUEST);
        return SignupForm.fromProviderUser(connection.fetchUserProfile());
    } else {
        return new SignupForm();
    }
}

您需要创建自己的本地providerSignInUtils,以便它可以访问connectionFactoryLocatorconnectionRepository