{"record":{"id":"8780defeff42e5bf","repo":"spring-projects/spring-framework","slug":"no-beanfactory-available-anymore-probably-due-to-8780de","errorCode":null,"errorMessage":"No BeanFactory available anymore (probably due to serialization) - cannot resolve prototype advisor '{}'","messagePattern":"No BeanFactory available anymore \\(probably due to serialization\\) - cannot resolve prototype advisor '(.+?)'","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java","lineNumber":468,"sourceCode":"\t}\n\n\n\t/**\n\t * Return an independent advisor chain.\n\t * We need to do this every time a new prototype instance is returned,\n\t * to return distinct instances of prototype Advisors and Advices.\n\t */\n\tprivate List<Advisor> freshAdvisorChain() {\n\t\tAdvisor[] advisors = getAdvisors();\n\t\tList<Advisor> freshAdvisors = new ArrayList<>(advisors.length);\n\t\tfor (Advisor advisor : advisors) {\n\t\t\tif (advisor instanceof PrototypePlaceholderAdvisor ppa) {\n\t\t\t\tif (logger.isDebugEnabled()) {\n\t\t\t\t\tlogger.debug(\"Refreshing bean named '\" + ppa.getBeanName() + \"'\");\n\t\t\t\t}\n\t\t\t\t// Replace the placeholder with a fresh prototype instance resulting from a getBean lookup\n\t\t\t\tif (this.beanFactory == null) {\n\t\t\t\t\tthrow new IllegalStateException(\"No BeanFactory available anymore (probably due to \" +\n\t\t\t\t\t\t\t\"serialization) - cannot resolve prototype advisor '\" + ppa.getBeanName() + \"'\");\n\t\t\t\t}\n\t\t\t\tObject bean = this.beanFactory.getBean(ppa.getBeanName());\n\t\t\t\tAdvisor refreshedAdvisor = namedBeanToAdvisor(bean);\n\t\t\t\tfreshAdvisors.add(refreshedAdvisor);\n\t\t\t}\n\t\t\telse {\n\t\t\t\t// Add the shared instance.\n\t\t\t\tfreshAdvisors.add(advisor);\n\t\t\t}\n\t\t}\n\t\treturn freshAdvisors;\n\t}\n\n\t/**\n\t * Add all global interceptors and pointcuts.\n\t */\n\tprivate void addGlobalAdvisors(ListableBeanFactory beanFactory, String prefix) {","sourceCodeStart":450,"sourceCodeEnd":486,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-aop/src/main/java/org/springframework/aop/framework/ProxyFactoryBean.java#L450-L486","documentation":"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.","triggerScenarios":"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.","commonSituations":"Session replication / serialization of beans backed by ProxyFactoryBean with prototype advisors; distributed caches holding AOP proxies; restart-from-snapshot features.","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."],"exampleFix":"// before\nObject proxy = aopFactoryBean.getObject();\nsession.setAttribute(\"p\", proxy); // serialize\n\n// after\nsession.setAttribute(\"pName\", \"myPrototypeProxy\");\n// on read:\nObject proxy = appCtx.getBean((String) session.getAttribute(\"pName\"));","handlingStrategy":"fallback","validationCode":"// Detect before serializing a prototype-proxy\nboolean hasPrototypeAdvisors = Arrays.stream(pfb.getAdvisors())\n    .anyMatch(a -> a.getClass().getSimpleName().contains(\"Placeholder\"));\nif (hasPrototypeAdvisors) { /* avoid serialization; store name instead */ }","typeGuard":"static boolean hasPrototypePlaceholders(Advisor[] advisors) {\n  return Arrays.stream(advisors).anyMatch(a -> a.getClass().getName().contains(\"PrototypePlaceholderAdvisor\"));\n}","tryCatchPattern":"try { List<Advisor> fresh = pfb.getAdvisors()...; }\ncatch (IllegalStateException e) {\n  if (e.getMessage().contains(\"prototype advisor\")) { /* re-resolve from BeanFactory */ }\n  throw e;\n}","preventionTips":["Use singleton-scoped advisors when proxies must cross serialization boundaries.","Re-resolve prototype proxies from the BeanFactory instead of deserializing them."],"tags":["spring-aop","proxyfactorybean","serialization","prototype","configuration"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}