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 prototype advisor '{}' What it means
Thrown as IllegalStateException by ProxyFactoryBean.freshAdvisorChain when refreshing a PrototypePlaceholderAdvisor (an interceptor bean declared prototype-scoped) but this.beanFactory is null. Like the other 'No BeanFactory available anymore' errors, this happens because the transient beanFactory is gone after deserialization and the prototype advisor needs to be re-resolved from the factory.
Source
Thrown at spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java:468
}
/**
* Return an independent advisor chain.
* We need to do this every time a new prototype instance is returned,
* to return distinct instances of prototype Advisors and Advices.
*/
private List<Advisor> freshAdvisorChain() {
Advisor[] advisors = getAdvisors();
List<Advisor> freshAdvisors = new ArrayList<>(advisors.length);
for (Advisor advisor : advisors) {
if (advisor instanceof PrototypePlaceholderAdvisor ppa) {
if (logger.isDebugEnabled()) {
logger.debug("Refreshing bean named '" + ppa.getBeanName() + "'");
}
// Replace the placeholder with a fresh prototype instance resulting from a getBean lookup
if (this.beanFactory == null) {
throw new IllegalStateException("No BeanFactory available anymore (probably due to " +
"serialization) - cannot resolve prototype advisor '" + ppa.getBeanName() + "'");
}
Object bean = this.beanFactory.getBean(ppa.getBeanName());
Advisor refreshedAdvisor = namedBeanToAdvisor(bean);
freshAdvisors.add(refreshedAdvisor);
}
else {
// Add the shared instance.
freshAdvisors.add(advisor);
}
}
return freshAdvisors;
}
/**
* Add all global interceptors and pointcuts.
*/
private void addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix) {View on GitHub (pinned to 69bf83ad71)
Solutions
- Avoid serializing ProxyFactoryBean / its proxies; re-resolve the bean from the BeanFactory after deserialization.
- Switch prototype-scoped advisors to singletons if cross-JVM serialization is needed, so no re-resolution occurs.
- Store a key and call getBean(name) on the receiving side instead of shipping the proxy.
Example fix
// before
Object proxy = aopFactoryBean.getObject();
session.setAttribute("p", proxy); // serialize
// after
session.setAttribute("pName", "myPrototypeProxy");
// on read:
Object proxy = appCtx.getBean((String) session.getAttribute("pName")); Defensive patterns
Strategy: fallback
Validate before calling
// Detect before serializing a prototype-proxy
boolean hasPrototypeAdvisors = Arrays.stream(pfb.getAdvisors())
.anyMatch(a -> a.getClass().getSimpleName().contains("Placeholder"));
if (hasPrototypeAdvisors) { /* avoid serialization; store name instead */ } Type guard
static boolean hasPrototypePlaceholders(Advisor[] advisors) {
return Arrays.stream(advisors).anyMatch(a -> a.getClass().getName().contains("PrototypePlaceholderAdvisor"));
} Try / catch
try { List<Advisor> fresh = pfb.getAdvisors()...; }
catch (IllegalStateException e) {
if (e.getMessage().contains("prototype advisor")) { /* re-resolve from BeanFactory */ }
throw e;
} Prevention
- Use singleton-scoped advisors when proxies must cross serialization boundaries.
- Re-resolve prototype proxies from the BeanFactory instead of deserializing them.
When it happens
Trigger: Deserialized ProxyFactoryBean (or a singleton proxy in non-singleton mode) that has prototype-scoped advisors in its chain, then re-creating a prototype instance triggers freshAdvisorChain which hits the null beanFactory at line 467.
Common situations: Session replication / serialization of beans backed by ProxyFactoryBean with prototype advisors; distributed caches holding AOP proxies; restart-from-snapshot features.
Related errors
- 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
- Can only use global advisors or interceptors with a Listable
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/8780defeff42e5bf.
Report an issue: GitHub.