{"record":{"id":"33cf25b757eaae53","repo":"alibaba/spring-cloud-alibaba","slug":"applicationcontext-not-set","errorCode":null,"errorMessage":"ApplicationContext not set","messagePattern":"ApplicationContext not set","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"critical","filePath":"spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java","lineNumber":785,"sourceCode":"\t\t\t\tif (dataId != null && group != null && key != null && defaultValue != null) {\n\t\t\t\t\thandleBeanNacosConfigAnnotation(dataId, group, key, true, beanName, bean, defaultValue);\n\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t}\n\n\t}\n\n\t@Override\n\tpublic void setApplicationContext(ApplicationContext applicationContext) throws BeansException {\n\t\tthis.applicationContext = applicationContext;\n\t}\n\n\tprivate NacosConfigManager getNacosConfigManager() {\n\t\tif (this.nacosConfigManager == null) {\n\t\t\tif (this.applicationContext == null) {\n\t\t\t\tthrow new IllegalStateException(\"ApplicationContext not set\");\n\t\t\t}\n\t\t\tnacosConfigManager = this.applicationContext.getBean(NacosConfigManager.class);\n\n\t\t}\n\t\treturn nacosConfigManager;\n\t}\n\n\tprivate static String[] getNullPropertyNames(Object source) {\n\t\tfinal BeanWrapper src = new BeanWrapperImpl(source);\n\t\tPropertyDescriptor[] pds = src.getPropertyDescriptors();\n\n\t\tSet<String> nullPropertyNames = new HashSet<>();\n\t\tfor (PropertyDescriptor pd : pds) {\n\t\t\tString propertyName = pd.getName();\n\t\t\ttry {\n\t\t\t\tObject propertyValue = src.getPropertyValue(propertyName);\n\t\t\t\tif (propertyValue == null) {\n\t\t\t\t\tnullPropertyNames.add(propertyName);","sourceCodeStart":767,"sourceCodeEnd":803,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/annotation/NacosAnnotationProcessor.java#L767-L803","documentation":"Thrown by NacosAnnotationProcessor.getNacosConfigManager() when the ApplicationContext field is still null. The processor implements ApplicationContextAware via setApplicationContext(...), so this field is populated during the normal Spring bean lifecycle; reaching this guard means getNacosConfigManager() was invoked before setApplicationContext ran, i.e., during an earlier lifecycle phase than the processor is ready for.","triggerScenarios":"A bean-post-processing or initialization callback in NacosAnnotationProcessor that calls getNacosConfigManager() before the ApplicationContext has been injected (e.g., an early BeanFactoryPostProcessor-style hook, or a manually instantiated processor that was never wired by Spring).","commonSituations":"Custom bootstrap that instantiates NacosAnnotationProcessor outside Spring; a bean-creation-order change in an upgrade that calls config logic before the ApplicationContext is set; using the processor in a context where ApplicationContextAware is not honored.","solutions":["Let Spring create and manage NacosAnnotationProcessor so setApplicationContext is invoked before use.","If you must drive it manually, call setApplicationContext(ctx) before any method that resolves NacosConfigManager.","Check for early-eager initialization (@Autowired/constructor use of the processor) that defeats the ApplicationContextAware ordering."],"exampleFix":"// before (manual, misses context wiring)\nNacosAnnotationProcessor p = new NacosAnnotationProcessor();\np.process(...); // -> IllegalStateException\n// after\nNacosAnnotationProcessor p = ctx.getBean(NacosAnnotationProcessor.class);\np.setApplicationContext(ctx); // if driven manually\np.process(...);","handlingStrategy":"validation","validationCode":"// If driving the processor manually, ensure the context is set first.\nif (processor instanceof ApplicationContextAware) {\n    ((ApplicationContextAware) processor).setApplicationContext(ctx);\n}\nNacosConfigManager mgr = processor.getNacosConfigManager();","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Let Spring manage NacosAnnotationProcessor so setApplicationContext runs.","Do not instantiate the processor directly outside Spring.","Avoid eager initialization that uses the processor before its lifecycle callback."],"tags":["nacos","config","spring-lifecycle","application-context","initialization"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}