2
我試圖將xml配置的bean轉換爲JavaConfig。 XML版本工作,但使用JavaConfig版本時,我不斷收到錯誤:Spring Framework:沒有可用的BeanFactory(可能是由於序列化)
Caused by: java.lang.IllegalStateException: No BeanFactory available anymore (probably due to serialization) - cannot resolve interceptor names [cacheAdvisor]
at org.springframework.aop.framework.ProxyFactoryBean.initializeAdvisorChain(ProxyFactoryBean.java:423)
使用XML配置:
<bean id="contentLogic" class="org.springframework.aop.framework.ProxyFactoryBean">
<property name="interceptorNames">
<list>
<value>cacheAdvisor</value>
</list>
</property>
<property name="proxyInterfaces" value="com.company.logic.ContentLogic"/>
<property name="target">
<bean class="com.company.logic.ContentLogicImpl"/>
</property>
</bean>
不工作JavaConfig:
@Configuration
public class SpringConfiguration {
@Bean
public ContentLogic getRealContentLogic() throws ClassNotFoundException {
ProxyFactoryBean factory = new ProxyFactoryBean();
factory.setInterceptorNames(new String[]{"cacheAdvisor"});
factory.setTargetClass(ContentLogicImpl.class);
factory.setProxyInterfaces(new Class[]{ContentLogic.class});
return (ContentLogic) factory.getObject();
}
}
由於我們現在使用了@Component,所以除XML之外的所有其他bean都已從XML中刪除。所以這將是很好的擺脫最後一個:-) 我會嘗試你的建議,並報告回來! –
工作很好,謝謝! 這是附加的代碼: factory.setBeanFactory(beanFactory); –