我正在使用spring-security-oauth2的1.0.0.RELEASE版本。我的Maven依赖是:
<dependency>
<groupId>org.springframework.security.oauth</groupId>
<artifactId>spring-security-oauth2</artifactId>
<version>1.0.0.RELEASE</version>
</dependency>
这是我在应用程序上下文中的bean定义。
<bean id="inMemoryTokenStore"
class="org.springframework.security.oauth2.provider.token.InMemoryTokenStore">
</bean>
<bean id="tokenServices"
class="org.springframework.security.oauth2.provider.token.DefaultTokenServices">
<property name="tokenStore" ref="inMemoryTokenStore" />
</bean>
<bean id="oAuth2AuthenticationManager"
class="org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationManager">
<property name="tokenServices" ref="tokenServices" />
</bean>
<bean id="oAuth2AuthProcessingFilter"
class="org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationProcessingFilter">
<property name="authenticationManager" ref="oAuth2AuthenticationManager" />
<qualifier value="oAuth2"/>
</bean>
当我尝试创建bean时,我得到以下奇怪的异常,但没有具体的信息。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'oAuth2AuthProcessingFilter' defined in class path resource [com/etrade/spring/security/oauth/web/application/OAuth2Filters-context.xml]: Initialization of bean failed; nested exception is java.lang.reflect.MalformedParameterizedTypeException
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:527)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:103)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:1)
at org.springframework.test.context.support.DelegatingSmartContextLoader.loadContext(DelegatingSmartContextLoader.java:228)
at org.springframework.test.context.TestContext.loadApplicationContext(TestContext.java:124)
at org.springframework.test.context.TestContext.getApplicationContext(TestContext.java:148)
... 28 more
Caused by: java.lang.reflect.MalformedParameterizedTypeException
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.validateConstructorArguments(ParameterizedTypeImpl.java:42)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.<init>(ParameterizedTypeImpl.java:35)
at sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl.make(ParameterizedTypeImpl.java:77)
at sun.reflect.generics.factory.CoreReflectionFactory.makeParameterizedType(CoreReflectionFactory.java:86)
at sun.reflect.generics.visitor.Reifier.visitClassTypeSignature(Reifier.java:122)
at sun.reflect.generics.tree.ClassTypeSignature.accept(ClassTypeSignature.java:31)
at sun.reflect.generics.repository.ConstructorRepository.getParameterTypes(ConstructorRepository.java:76)
at java.lang.reflect.Method.getGenericParameterTypes(Method.java:282)
at org.springframework.core.GenericTypeResolver.getTargetType(GenericTypeResolver.java:65)
at org.springframework.core.GenericTypeResolver.resolveParameterType(GenericTypeResolver.java:80)
at org.springframework.beans.GenericTypeAwarePropertyDescriptor.getWriteMethodParameter(GenericTypeAwarePropertyDescriptor.java:150)
at org.springframework.beans.GenericTypeAwarePropertyDescriptor.getPropertyType(GenericTypeAwarePropertyDescriptor.java:132)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.isExcludedFromDependencyCheck(AbstractAutowireCapableBeanFactory.java:1269)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.filterPropertyDescriptorsForDependencyCheck(AbstractAutowireCapableBeanFactory.java:1245)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:1101)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:517)
... 41 more
我在Stackoverflow上阅读了类似的问题,并尝试了一些建议,例如验证没有Spring版本冲突,但没有任何帮助。请告诉我这是如何解决的。
答案 0 :(得分:0)
我以为我会对这个问题有所了解,因为我也在挖掘这个问题。
如果我们查看OAuth2AuthenticationProcessingFilter.java,则会将authenticationDetailsSource
的类型设置为AuthenticationDetailsSource<HttpServletRequest, ?>
,但至少在版本3.1.0.M1之前不会模板化(请参阅{{3 }和SEC-1486)。
缺点是,spring-security-oauth 需要 3.1.x的spring security才能工作。我会尝试一个混乱的解决方法,直到我们可以升级它,因为我们依赖于需要3.0.x的grails插件。