spring-projects/spring-framework · error · BeanInitializationException
Could not load properties: ${ex.getMessage()}
Error message
Could not load properties: ${ex.getMessage()} What it means
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.
Source
Thrown at spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyResourceConfigurer.java:89
/**
* {@linkplain #mergeProperties Merge}, {@linkplain #convertProperties convert} and
* {@linkplain #processProperties process} properties against the given bean factory.
* @throws BeanInitializationException if any properties cannot be loaded
*/
@Override
public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {
try {
Properties mergedProps = mergeProperties();
// Convert the merged properties, if necessary.
convertProperties(mergedProps);
// Let the subclass process the properties.
processProperties(beanFactory, mergedProps);
}
catch (IOException ex) {
throw new BeanInitializationException("Could not load properties: " + ex.getMessage(), ex);
}
}
/**
* Convert the given merged properties, converting property values
* if necessary. The result will then be processed.
* <p>The default implementation will invoke {@link #convertPropertyValue}
* for each property value, replacing the original with the converted value.
* @param props the Properties to convert
* @see #processProperties
*/
protected void convertProperties(Properties props) {
Enumeration<?> propertyNames = props.propertyNames();
while (propertyNames.hasMoreElements()) {
String propertyName = (String) propertyNames.nextElement();
String propertyValue = props.getProperty(propertyName);
String convertedValue = convertProperty(propertyName, propertyValue);
if (!ObjectUtils.nullSafeEquals(propertyValue, convertedValue)) {View on GitHub (pinned to 69bf83ad71)
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.
Example fix
<!-- before (broken): file not on classpath --> <bean class="...PropertyPlaceholderConfigurer"> <property name="location" value="classpath:missing.properties"/> </bean> <!-- after: correct path + tolerate absence --> <bean class="...PropertyPlaceholderConfigurer"> <property name="location" value="classpath:application.properties"/> <property name="ignoreResourceNotFound" value="true"/> </bean>
Defensive patterns
Strategy: try-catch
Validate before calling
for (Resource r : configurer.getLocations()) {
if (!r.exists()) {
throw new IllegalStateException("Properties resource not found: " + r);
}
} Try / catch
try {
context.refresh();
} catch (BeanInitializationException ex) {
if (ex.getMessage().startsWith("Could not load properties")) {
// fix the path or enable setIgnoreResourceNotFound(true), then retry
}
throw ex;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Error registering bean definition
- Could not process key '
- Invalid key '
- CustomAutowireConfigurer needs to operate on a DefaultListab
- Invalid value [{}] for custom qualifier type: needs to be Cl
AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09).
Data as JSON: /api/errors/e3c49dc7e3c090b8.
Report an issue: GitHub.