我正在尝试将 xml 配置的 bean 转换为 JavaConfig。xml 版本正在运行,但在使用 JavaConfig 版本时我不断收到错误消息:
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();
}
}