spring boot callbackUrl ConnectSupport

[亡魂溺海] 提交于 2020-02-07 17:14:34

问题


I want to overload callbackUrl in ConnectSupport

I use Spring boot Connect : org.springframework.social:spring-social-core:jar:1.1.0.RELEASE:compile

@Bean
public ConnectController connectController(
        ConnectionFactoryLocator connectionFactoryLocator,
        ConnectionRepository connectionRepository) {

    ConnectController controller = new ConnectController(connectionFactoryLocator,
            connectionRepository);

        controller.set callbackUrl  ??
        return controller;

}

回答1:


Spring Social Api is available here. You need to call the setApplicationUrl().

@Bean
public ConnectController connectController(ConnectionFactoryLocator connectionFactoryLocator,
        ConnectionRepository connectionRepository) {

    ConnectController controller = new ConnectController(connectionFactoryLocator,
            connectionRepository);
        String url = "www.foo.com";
        controller.setApplicationUrl(url) ;
        return controller;

}



回答2:


At this point (NullPointerException problem) one way to solve the problem is to extend ConnectController (and ProviderSignInController which suffers the same issue) and fix the offending portion of the code yourself. Just adding the classes into project works. Is it elegant? Well...

/*******************************************************************/
//RedirectedConnectController.java

public class RedirectedConnectController extends ConnectController {

    @Value("${application.url}")
    private String appUrl;

    public RedirectedConnectController(ConnectionFactoryLocator connectionFactoryLocator, 
                                       ConnectionRepository connectionRepository) {
        super(connectionFactoryLocator, connectionRepository);
    }

    /*
     * This is the method, which should be called BEFORE setApplicationUrl
     * but obviously is not. 
     */    
    @Override
    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();
        setApplicationUrl(appUrl);
    }
}
/*******************************************************************/
//RedirectedSignInController.java

@Controller
public class RedirectedSignInController extends ProviderSignInController {

    @Value("${application.url}")
    private String appUrl;

    @Inject
    public RedirectedSignInController(ConnectionFactoryLocator connectionFactoryLocator, 
                                      UsersConnectionRepository usersConnectionRepository, 
                                      SignInAdapter signInAdapter) {
        super(connectionFactoryLocator, usersConnectionRepository, signInAdapter);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        super.afterPropertiesSet();
        setApplicationUrl(appUrl);
    }
}


来源:https://stackoverflow.com/questions/27593441/spring-boot-callbackurl-connectsupport

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!