2015-04-03 101 views
1

春天社交版1.1.0.RELEASE,我需要建立applicationUrl爲ProviderSignInController,我的應用程序(一個Tomcat應用程序)在代理(Apache Web服務器)託管。根據Spring Social document,我將它設置如下:春天社會applicationURL設置例外

<bean id="providerSignInController" 
    class="org.springframework.social.connect.web.ProviderSignInController"> 
    <property name="signInUrl" value="/accounts/login" /> 
    <property name="signUpUrl" value="/accounts/signup" /> 
    <property name="postSignInUrl" value="/accounts/profile" /> 
    <property name="applicationUrl" value="${applicationUrl}" /> 
</bean> 

但是,部署應用程序時,我得到在Tomcat中的異常catalina.out中說:

PropertyAccessException 1: 
org.springframework.beans.MethodInvocationException: Property 
'applicationUrl' threw exception; nested exception is 
java.lang.NullPointerException>org.springframework.beans.factory.BeanCreationException: 
Error creating bean with name 
'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping#0' 
defined in ServletContext resource [/WEB-INF/spring-servlet.xml]: 
Initialization of bean failed; nested exception is 
org.springframework.beans.factory.BeanCreationException: Error creating 
bean with name 'providerSignInController' defined in ServletContext 
resource [/WEB-INF/spring-servlet.xml]: Error setting property values; 
nested exception is 
org.springframework.beans.PropertyBatchUpdateException; nested 
PropertyAccessExceptions (1) are: 
PropertyAccessException 1: 
org.springframework.beans.MethodInvocationException: Property 
'applicationUrl' threw exception; nested exception is 
java.lang.NullPointerException 
     at 
org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527) 

任何建議嗎?謝謝。

+0

你已經在你的屬性中設置了'applicationUrl'嗎? – 2015-04-04 16:10:09

+0

是,所推薦的春天社會文檔(http://docs.spring.io/spring-social/docs/1.1.0.RELEASE/reference/htmlsingle/#enabling-provider-sign-in-with-code- providersignincontroller-code),應用程序URL的值在屬性文件中被外化。順便說一句,如果我沒有在bean providerSignInController的聲明中設置property applicationUrl,那麼可以毫無問題地創建bean。也就是說,屬性signInUrl,signUpUrl和postSignInUrl沒有問題。 – Yuci 2015-04-05 21:50:18

+0

然後,你能不能告訴我們的屬性文件,以及如何配置讀取屬性文件的春天嗎?以及其他屬性(如signInUrl,signUpUrl)沒有任何問題,因爲您直接設置這些值。 – 2015-04-06 03:40:36

回答

1

它應該是Spring Social version 1.1.0.RELEASE中的類ProviderSignInController的一個bug。在類ProviderSignInController,connectSupport被屬性被設置之後創建的:

public void afterPropertiesSet() throws Exception { 
    this.connectSupport = new ConnectSupport(sessionStrategy); 
    this.connectSupport.setUseAuthenticateUrl(true); 
}; 

因此被調用方法setApplicationUrl時,connectSupport仍然是空。

現在,當我按照下面所示的方式進行配置時,它可以工作。或者,如果我恢復到版本1.0.3.RELEASE,它也可以正常工作。

<bean id="providerSignInController" 
    class="org.springframework.social.connect.web.ProviderSignInController"> 
    <property name="signInUrl" value="/accounts/login" /> 
    <property name="signUpUrl" value="/accounts/signup" /> 
    <property name="postSignInUrl" value="/accounts/profile" /> 
</bean> 
<bean 
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"> 
    <property name="targetObject" ref="providerSignInController" /> 
    <property name="targetMethod" value="setApplicationUrl" /> 
    <property name="arguments"> 
     <list> 
      <bean class="java.lang.String"> 
       <constructor-arg value="${applicationUrl}" /> 
      </bean> 
     </list> 
    </property> 
</bean> 

後續

這個問題已經在社會春季版1.1.3.RELEASE解決。在課堂上ProviderSignInController,方法afterPropertiesSet方法已經更新到:

public void afterPropertiesSet() throws Exception { 
    this.connectSupport = new ConnectSupport(sessionStrategy); 
    this.connectSupport.setUseAuthenticateUrl(true); 
    if (this.applicationUrl != null) { 
     this.connectSupport.setApplicationUrl(applicationUrl); 
    } 
}; 

其結果是,上面給出的配置的解決辦法,現在(順便說一下,不會與春天社會1.1.3.RELEASE版本更多的工作)可以簡化爲:

<bean id="providerSignInController" 
    class="org.springframework.social.connect.web.ProviderSignInController"> 
    <property name="signInUrl" value="/accounts/login" /> 
    <property name="signUpUrl" value="/accounts/signup" /> 
    <property name="postSignInUrl" value="/accounts/profile" /> 
    <property name="applicationUrl" value="${applicationUrl}" /> 
</bean>