spring-projects/spring-framework · error · IllegalStateException
No BeanFactory available anymore (probably due to serializat
Error message
No BeanFactory available anymore (probably due to serialization) - cannot resolve interceptor names {Arrays.toString(interceptorNames)} What it means
initializeAdvisorChain() needs a BeanFactory to materialize the interceptor/advisor beans named in interceptorNames. When beanFactory is null (it is transient and lost on Java serialization), resolving those names is impossible, so Spring throws IllegalStateException. The message explicitly blames serialization because that is the documented reason the field becomes null after deserialization.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java:411
}
// Treat it as a target bean if we can't tell.
if (logger.isDebugEnabled()) {
logger.debug("Could not determine type of bean with name '" + beanName +
"' - assuming it is neither an Advisor nor an Advice");
}
return false;
}
/**
* Create the advisor (interceptor) chain. Advisors that are sourced
* from a BeanFactory will be refreshed each time a new prototype instance
* is added. Interceptors added programmatically through the factory API
* are unaffected by such changes.
*/
private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException {
if (!this.advisorChainInitialized && !ObjectUtils.isEmpty(this.interceptorNames)) {
if (this.beanFactory == null) {
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
"- cannot resolve interceptor names " + Arrays.toString(this.interceptorNames));
}
// Globals can't be last unless we specified a targetSource using the property...
if (this.interceptorNames[this.interceptorNames.length - 1].endsWith(GLOBAL_SUFFIX) &&
this.targetName == null && this.targetSource == EMPTY_TARGET_SOURCE) {
throw new AopConfigException("Target required after globals");
}
// Materialize interceptor chain from bean names.
for (String name : this.interceptorNames) {
if (name.endsWith(GLOBAL_SUFFIX)) {
if (!(this.beanFactory instanceof ListableBeanFactory lbf)) {
throw new AopConfigException(
"Can only use global advisors or interceptors with a ListableBeanFactory");
}
addGlobalAdvisors(lbf, name.substring(0, name.length() - GLOBAL_SUFFIX.length()));
}View on GitHub (pinned to e8729d0438)
Solutions
- Do not serialize the ProxyFactoryBean itself; serialize only the proxy and rely on Spring to rebuild the factory on the other side.
- Re-obtain the proxy from the ApplicationContext after deserialization rather than reusing a deserialized copy.
- If you must carry state across, mark the proxy as transient and refresh it from the context post-serialization.
Example fix
// before
session.setAttribute("proxy", proxyFactoryBean); // serializes FactoryBean
// after: store only the bean name, look it up after
session.setAttribute("proxyBeanName", "myService");
MyService proxy = ctx.getBean("myService", MyService.class); Defensive patterns
Strategy: validation
Validate before calling
// Do not serialize ProxyFactoryBean; before using one post-serialization, reattach it
ProxyFactoryBean pfb = ...;
if (pfb.getBeanFactory() == null && pfb.getInterceptorNames() != null) {
throw new IllegalStateException("ProxyFactoryBean lost its BeanFactory via serialization; re-resolve from context.");
} Prevention
- Never put a ProxyFactoryBean in an HTTP session or distributed cache.
- Serialize only the proxy or a bean name; rebuild the factory from the ApplicationContext.
- Mark proxies/factory beans transient and re-resolve after deserialization.
When it happens
Trigger: Serializing a ProxyFactoryBean (or its proxy) and then triggering re-initialization of the advice chain on the deserialized instance; programmatically calling adviceChanged/setInterceptorNames after the bean was deserialized.
Common situations: Storing a Spring AOP proxy or the FactoryBean in an HTTP session or distributed cache that serializes it; remote invocation scenarios; calling getObject() on a deserialized ProxyFactoryBean whose interceptorNames still need resolving.
Related errors
- Can only use global advisors or interceptors with a Listable
- No BeanFactory available anymore (probably due to serializat
- No BeanFactory available anymore (probably due to serializat
- Cannot determine target class for proxy
- Target required after globals
AI-assisted analysis of spring-projects/spring-framework@e8729d0438 (2026-08-04).
Data as JSON: /data/errors/6fa4d2edc5b21c49.json.
Report an issue: GitHub.