0

我正在使用自定义 FactoryBean 来构建一组单例对象。从 FactoryBean 中,我以编程方式调用“autowireBeanProperties”以将依赖项注入到 bean 中。

context.getAutowireCapableBeanFactory().autowireBeanProperties(o, AutowireCapableBeanFactory.AUTOWIRE_BY_NAME, false);

(我知道这不是最佳方案,但我有理由以这种方式设计事物,并且我计划进行更改,但它需要的时间比我想象的要多)

其中一个依赖项是自定义范围的 bean,我们将其称为“userSession”范围。

我收到以下错误:

Property 'scopedBean' threw exception; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'scopedTarget.connector': Scope 'userSession' is not active for the current thread; consider defining a scoped proxy for this bean if you intend to refer to it from a singleton; nested exception is java.lang.IllegalStateException: Unknown identity: null

我尝试使用自定义 ScopedProxy (仅在方法调用时实例化内部 userSession-scoped 对象),但结果是相同的。堆栈看起来像这样:

UserSessionScope.get(String, ObjectFactory) line: 23    
DefaultListableBeanFactory(AbstractBeanFactory).doGetBean(String, Class<T>, Object[], boolean) line: 329    
DefaultListableBeanFactory(AbstractBeanFactory).getBean(String) line: 194   
SimpleBeanTargetSource.getTarget() line: 33 
JdkDynamicAopProxy.invoke(Object, Method, Object[]) line: 184   
$Proxy0.setScopedBean(IScopedBean) line: not available  
MySingletonBean.setScopedBean(IScopedBean) line: 51
NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]  
NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39  
DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25  
Method.invoke(Object, Object...) line: 597  
BeanWrapperImpl.setPropertyValue(BeanWrapperImpl$PropertyTokenHolder, PropertyValue) line: 1134 
BeanWrapperImpl.setPropertyValue(PropertyValue) line: 904   
BeanWrapperImpl(AbstractPropertyAccessor).setPropertyValues(PropertyValues, boolean, boolean) line: 75  
BeanWrapperImpl(AbstractPropertyAccessor).setPropertyValues(PropertyValues) line: 57    
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).applyPropertyValues(String, BeanDefinition, BeanWrapper, PropertyValues) line: 1424  
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).populateBean(String, RootBeanDefinition, BeanWrapper) line: 1132 
DefaultListableBeanFactory(AbstractAutowireCapableBeanFactory).autowireBeanProperties(Object, int, boolean) line: 379   
MyFactoryBean.processInjection(Object) line: 68

我无法想象为什么在实例化阶段调用了调用......我没有这样做的逻辑......

另一件事是:我没有名为“scopedTarget.connector”的 bean。

感谢您提供任何线索

(顺便说一句:我使用的是 Spring 3.2 版本)

4

1 回答 1

0

好吧,这是我的错。我想知道为什么我会得到那个不相关的堆栈跟踪......

问题出在其他地方...

于 2013-06-03T16:20:50.490 回答