0
我正在使用自定義FactoryBean來構建一組單身對象。在FactoryBean中,我以編程方式調用'autowireBeanProperties'來將依賴關係注入到bean中。FactoryBean和自定義範圍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範圍的對象),但結果是相同的。 堆棧似乎是這樣的:
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。
感謝任何線索
(BTW:我使用Spring 3.2版本)