Spring社交应用URL设置异常
Spring Social applicationURL setup exception
对于 Spring 社交版本 1.1.0.RELEASE,我需要为 ProviderSignInController 设置 applicationUrl,因为我的应用程序(Tomcat 应用程序)托管在代理后面( Apache 网络服务器)。根据Spring Social document,我设置如下:
<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)
有什么建议吗?谢谢
这应该是 class ProviderSignInController 在 Spring 社交版本 1.1.0.RELEASE 中的错误。在 class ProviderSignInController 中,connectSupport 在设置属性后创建:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
};
因此调用方法 setApplicationUrl 时,connectSupport 仍然为 null。
现在当我按照下面所示的方式配置它时,它就可以工作了。或者,如果我恢复到 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>
跟进
此问题已在 Spring 社交版本 1.1.3.RELEASE 中解决。在 class ProviderSignInController 中,方法 afterPropertiesSet 已更新为:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
if (this.applicationUrl != null) {
this.connectSupport.setApplicationUrl(applicationUrl);
}
};
因此,上面给出的解决方法(顺便说一句,不再适用于 Spring 社交版本 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>
对于 Spring 社交版本 1.1.0.RELEASE,我需要为 ProviderSignInController 设置 applicationUrl,因为我的应用程序(Tomcat 应用程序)托管在代理后面( Apache 网络服务器)。根据Spring Social document,我设置如下:
<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)
有什么建议吗?谢谢
这应该是 class ProviderSignInController 在 Spring 社交版本 1.1.0.RELEASE 中的错误。在 class ProviderSignInController 中,connectSupport 在设置属性后创建:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
};
因此调用方法 setApplicationUrl 时,connectSupport 仍然为 null。
现在当我按照下面所示的方式配置它时,它就可以工作了。或者,如果我恢复到 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>
跟进
此问题已在 Spring 社交版本 1.1.3.RELEASE 中解决。在 class ProviderSignInController 中,方法 afterPropertiesSet 已更新为:
public void afterPropertiesSet() throws Exception {
this.connectSupport = new ConnectSupport(sessionStrategy);
this.connectSupport.setUseAuthenticateUrl(true);
if (this.applicationUrl != null) {
this.connectSupport.setApplicationUrl(applicationUrl);
}
};
因此,上面给出的解决方法(顺便说一句,不再适用于 Spring 社交版本 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>