{"record":{"id":"e3c49dc7e3c090b8","repo":"spring-projects/spring-framework","slug":"could-not-load-properties-ex-getmessage","errorCode":null,"errorMessage":"Could not load properties: ${ex.getMessage()}","messagePattern":"Could not load properties: (.+?)","errorType":"exception","errorClass":"BeanInitializationException","httpStatus":null,"severity":"error","filePath":"spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyResourceConfigurer.java","lineNumber":89,"sourceCode":"\n\t/**\n\t * {@linkplain #mergeProperties Merge}, {@linkplain #convertProperties convert} and\n\t * {@linkplain #processProperties process} properties against the given bean factory.\n\t * @throws BeanInitializationException if any properties cannot be loaded\n\t */\n\t@Override\n\tpublic void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {\n\t\ttry {\n\t\t\tProperties mergedProps = mergeProperties();\n\n\t\t\t// Convert the merged properties, if necessary.\n\t\t\tconvertProperties(mergedProps);\n\n\t\t\t// Let the subclass process the properties.\n\t\t\tprocessProperties(beanFactory, mergedProps);\n\t\t}\n\t\tcatch (IOException ex) {\n\t\t\tthrow new BeanInitializationException(\"Could not load properties: \" + ex.getMessage(), ex);\n\t\t}\n\t}\n\n\t/**\n\t * Convert the given merged properties, converting property values\n\t * if necessary. The result will then be processed.\n\t * <p>The default implementation will invoke {@link #convertPropertyValue}\n\t * for each property value, replacing the original with the converted value.\n\t * @param props the Properties to convert\n\t * @see #processProperties\n\t */\n\tprotected void convertProperties(Properties props) {\n\t\tEnumeration<?> propertyNames = props.propertyNames();\n\t\twhile (propertyNames.hasMoreElements()) {\n\t\t\tString propertyName = (String) propertyNames.nextElement();\n\t\t\tString propertyValue = props.getProperty(propertyName);\n\t\t\tString convertedValue = convertProperty(propertyName, propertyValue);\n\t\t\tif (!ObjectUtils.nullSafeEquals(propertyValue, convertedValue)) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/spring-projects/spring-framework/blob/69bf83ad716d0cfc4b0520a19b4d8b24c79d1538/spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyResourceConfigurer.java#L71-L107","documentation":"Thrown by PropertyResourceConfigurer.postProcessBeanFactory() as a BeanInitializationException wrapping an IOException from mergeProperties(). PropertyResourceConfigurer (base of PropertyPlaceholderConfigurer and PropertyOverrideConfigurer) loads properties from configured locations/Location resources before applying them; if any resource cannot be read, opened, or parsed, the original IOException's message is appended. This is an I/O failure at context refresh, not a bean-resolution problem.","triggerScenarios":"A location that does not exist (e.g. classpath:foo.properties when foo.properties is absent), is unreadable (permissions), is malformed (depends on loader), or a network/filesystem IOException while opening the Resource. Multiple locations where any one fails. Using a ${}-placeholder inside the location itself that resolves to a non-existent path.","commonSituations":"Properties file moved or renamed. Wrong classpath root / module not exporting the resource. Profile-specific file not present. File locked by another process. Typo in the location path. Packaging issue where the properties file didn't get included in the jar.","solutions":["Check the IOException detail for the offending resource path and verify it exists at that exact location (classpath: vs file: vs classpath*:).","Make the resource optional with setIgnoreResourceNotFound(true) on the configurer, or use Spring's resource patterns (classpath*:) carefully.","If the location contains placeholders, ensure they resolve before the configurer runs, or hardcode the path.","Rebuild/repackage to ensure the properties file is actually included in the artifact."],"exampleFix":"<!-- before (broken): file not on classpath -->\n<bean class=\"...PropertyPlaceholderConfigurer\">\n  <property name=\"location\" value=\"classpath:missing.properties\"/>\n</bean>\n<!-- after: correct path + tolerate absence -->\n<bean class=\"...PropertyPlaceholderConfigurer\">\n  <property name=\"location\" value=\"classpath:application.properties\"/>\n  <property name=\"ignoreResourceNotFound\" value=\"true\"/>\n</bean>","handlingStrategy":"try-catch","validationCode":"for (Resource r : configurer.getLocations()) {\n    if (!r.exists()) {\n        throw new IllegalStateException(\"Properties resource not found: \" + r);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    context.refresh();\n} catch (BeanInitializationException ex) {\n    if (ex.getMessage().startsWith(\"Could not load properties\")) {\n        // fix the path or enable setIgnoreResourceNotFound(true), then retry\n    }\n    throw ex;\n}","preventionTips":["Use setIgnoreResourceNotFound(true) when a properties file is optional.","Validate resource existence in a startup health check before refresh.","Pin down classpath roots and ensure properties files are packaged into the jar/war.","Avoid placeholders inside location strings unless they resolve before the configurer runs."],"tags":["spring","properties","io","configuration","resource-loading"],"backgroundTag":null,"analyzedSha":"69bf83ad716d0cfc4b0520a19b4d8b24c79d1538","analyzedAt":"2026-08-09T15:32:58.770Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}