2014-10-20 60 views
0

我最近在当前的Spring项目中完成了spring-social的实现,但是我有一个仍然困扰我的独特问题:在我的SocialContext类(实现SocialConfigurer)中,我尝试定义目标网址,其中应用程序就会在登入后,以这样的方式尝试在ProviderSignInController中定义目标网址时发生NullPointerException

@Bean 
public ProviderSignInController providerSignInController(ConnectionFactoryLocator connectionFactoryLocator, UsersConnectionRepository connectionRepository) { 
    ProviderSignInController controller = new ProviderSignInController(connectionFactoryLocator, connectionRepository, signInAdapter); 
    controller.setApplicationUrl("/"); 
    return controller; 
} 

但是当我部署应用程序,这将失败,因为所造成的线controller.setApplicationUrl("/");(如果我评论这一行一个NullPointerException的,应用程序正确部署并运行没有问题,除非登录后返回到登录页面)。

任何人都知道如何解决这个问题?

回答

1

This thread似乎涵盖了类似的问题。基本上,如果你使用注释来配置Spring和安全,你可能会尝试这样的事情

@Configuration 
@EnableWebSecurity 
public class SecurityContext extends WebSecurityConfigurerAdapter { 
    ... 

    @Override 
    protected void configure(HttpSecurity http) throws Exception { 
     http 
      .formLogin() 
      .loginPage("/signin") 
      ... 
      // the rest of the configuration 
      ... 
      .and() 
      .rememberMe() 
      .and() 
      .apply(getSpringSocialConfigurer()); 
    } 

    private SpringSocialConfigurer getSpringSocialConfigurer() { 
     SpringSocialConfigurer config = new SpringSocialConfigurer(); 
     config.alwaysUsePostLoginUrl(true); 
     config.postLoginUrl("/"); 

     return config; 
    } 
} 
+0

我应该在哪里放置这个方法? – 2014-10-20 11:17:51

+0

看到我编辑的答案 – 2014-10-20 12:01:46

+0

好吧,这不会导致错误,但也没有任何效果(应用程序不会在登录后到达所需的位置)。 – 2014-10-20 13:54:11

相关问题