2014-10-20 61 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

相關問題