spring-projects/spring-framework · error · BeanInitializationException

Could not process key '

Error message

Could not process key '

What it means

Thrown by PropertyOverrideConfigurer.processProperties() as a BeanInitializationException wrapping any BeansException that occurs while applying a single override key (the key name is embedded in the message). It is raised only when ignoreInvalidKeys is false (the default). The wrapped cause is typically a NoSuchBeanDefinitionException (bean named in the key does not exist) or an invalid property path on the target bean.

Source

Thrown at spring-beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java:115

	 */
	public void setIgnoreInvalidKeys(boolean ignoreInvalidKeys) {
		this.ignoreInvalidKeys = ignoreInvalidKeys;
	}


	@Override
	protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties props)
			throws BeansException {

		for (Enumeration<?> names = props.propertyNames(); names.hasMoreElements();) {
			String key = (String) names.nextElement();
			try {
				processKey(beanFactory, key, props.getProperty(key));
			}
			catch (BeansException ex) {
				String msg = "Could not process key '" + key + "' in PropertyOverrideConfigurer";
				if (!this.ignoreInvalidKeys) {
					throw new BeanInitializationException(msg, ex);
				}
				if (logger.isDebugEnabled()) {
					logger.debug(msg, ex);
				}
			}
		}
	}

	/**
	 * Process the given key as 'beanName.property' entry.
	 */
	protected void processKey(ConfigurableListableBeanFactory factory, String key, String value)
			throws BeansException {

		int separatorIndex = key.indexOf(this.beanNameSeparator);
		if (separatorIndex == -1) {
			throw new BeanInitializationException("Invalid key '" + key +
					"': expected 'beanName" + this.beanNameSeparator + "property'");

View on GitHub (pinned to 69bf83ad71)

Solutions

  1. Read the wrapped cause: if NoSuchBeanDefinitionException, fix the bean name in the properties file or define the missing bean.
  2. If the property path is invalid, correct the property name to match a setter on the target bean's class.
  3. Set ignoreInvalidKeys=true (or <property name="ignoreInvalidKeys" value="true"/>) to skip non-matching keys when the file legitimately mixes override and other keys.
  4. Move non-override keys out of the file processed by PropertyOverrideConfigurer.

Example fix

# before (broken): 'datasorce' typo, no such bean
datasorce.url=jdbc:mysql:mydb
# after
dataSource.url=jdbc:mysql:mydb
Defensive patterns

Strategy: validation

Validate before calling

// Validate every override key references a real bean + writable property
for (String key : overrideProps.stringPropertyNames()) {
    int dot = key.indexOf('.');
    if (dot <= 0) continue;
    String beanName = key.substring(0, dot);
    if (!beanFactory.containsBeanDefinition(beanName)) {
        throw new IllegalStateException("Override references unknown bean: " + beanName);
    }
}

Type guard

static boolean isWellFormedOverrideKey(String key, String separator) {
    return key != null && key.indexOf(separator) > 0
        && key.indexOf(separator) < key.length() - 1;
}

Try / catch

try {
    context.refresh();
} catch (BeanInitializationException ex) {
    if (ex.getMessage().startsWith("Could not process key '")) {
        // extract the bad key, fix the properties file, or enable ignoreInvalidKeys
    }
    throw ex;
}

Prevention

When it happens

Trigger: An override properties line 'beanName.property=value' where 'beanName' is not a defined bean, or 'property' is not a writable property of that bean. A key whose bean-name segment refers to an alias or abstract bean definition. Type-mismatch when the literal value cannot be converted to the property type.

Common situations: Override properties file referencing a bean that was renamed or removed. Typo in bean name or property name. Loading an override file meant for a different context. Properties file containing unrelated keys (comments, environment hints) that still get parsed because ignoreInvalidKeys defaults to false.

Related errors


AI-assisted analysis of spring-projects/spring-framework@69bf83ad71 (2026-08-09). Data as JSON: /api/errors/a28fd02e61da5a49. Report an issue: GitHub.