PropertyOverrideConfigurer's "ignoreInvalidKeys" ignores invalid property names as well (SPR-5792)
This commit is contained in:
@@ -867,10 +867,17 @@ public class BeanWrapperImpl extends AbstractPropertyAccessor implements BeanWra
|
||||
if (pd == null || !pd.getWriteMethod().getDeclaringClass().isInstance(this.object)) {
|
||||
pd = getCachedIntrospectionResults().getPropertyDescriptor(actualName);
|
||||
if (pd == null || pd.getWriteMethod() == null) {
|
||||
PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass());
|
||||
throw new NotWritablePropertyException(
|
||||
getRootClass(), this.nestedPath + propertyName,
|
||||
matches.buildErrorMessage(), matches.getPossibleMatches());
|
||||
if (pv.isOptional()) {
|
||||
logger.debug("Ignoring optional value for property '" + actualName +
|
||||
"' - property not found on bean class [" + getRootClass().getName() + "]");
|
||||
return;
|
||||
}
|
||||
else {
|
||||
PropertyMatches matches = PropertyMatches.forProperty(propertyName, getRootClass());
|
||||
throw new NotWritablePropertyException(
|
||||
getRootClass(), this.nestedPath + propertyName,
|
||||
matches.buildErrorMessage(), matches.getPossibleMatches());
|
||||
}
|
||||
}
|
||||
pv.getOriginalPropertyValue().resolvedDescriptor = pd;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,8 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
|
||||
private Object source;
|
||||
|
||||
private boolean optional = false;
|
||||
|
||||
private boolean converted = false;
|
||||
|
||||
private Object convertedValue;
|
||||
@@ -80,6 +82,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
this.name = original.getName();
|
||||
this.value = original.getValue();
|
||||
this.source = original.getSource();
|
||||
this.optional = original.isOptional();
|
||||
this.converted = original.converted;
|
||||
this.convertedValue = original.convertedValue;
|
||||
this.conversionNecessary = original.conversionNecessary;
|
||||
@@ -99,6 +102,7 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
this.name = original.getName();
|
||||
this.value = newValue;
|
||||
this.source = original;
|
||||
this.optional = original.isOptional();
|
||||
this.conversionNecessary = original.conversionNecessary;
|
||||
this.resolvedTokens = original.resolvedTokens;
|
||||
this.resolvedDescriptor = original.resolvedDescriptor;
|
||||
@@ -136,6 +140,14 @@ public class PropertyValue extends BeanMetadataAttributeAccessor implements Seri
|
||||
return original;
|
||||
}
|
||||
|
||||
public void setOptional(boolean optional) {
|
||||
this.optional = optional;
|
||||
}
|
||||
|
||||
public boolean isOptional() {
|
||||
return this.optional;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this holder contains a converted value already (<code>true</code>),
|
||||
* or whether the value still needs to be converted (<code>false</code>).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,6 +23,7 @@ import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.BeanInitializationException;
|
||||
|
||||
/**
|
||||
@@ -84,9 +85,9 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer {
|
||||
|
||||
/**
|
||||
* Set whether to ignore invalid keys. Default is "false".
|
||||
* <p>If you ignore invalid keys, keys that do not follow the
|
||||
* 'beanName.property' format will just be logged as warning.
|
||||
* This allows to have arbitrary other keys in a properties file.
|
||||
* <p>If you ignore invalid keys, keys that do not follow the 'beanName.property' format
|
||||
* (or refer to invalid bean names or properties) will just be logged at debug level.
|
||||
* This allows one to have arbitrary other keys in a properties file.
|
||||
*/
|
||||
public void setIgnoreInvalidKeys(boolean ignoreInvalidKeys) {
|
||||
this.ignoreInvalidKeys = ignoreInvalidKeys;
|
||||
@@ -138,13 +139,15 @@ public class PropertyOverrideConfigurer extends PropertyResourceConfigurer {
|
||||
* Apply the given property value to the corresponding bean.
|
||||
*/
|
||||
protected void applyPropertyValue(
|
||||
ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
|
||||
ConfigurableListableBeanFactory factory, String beanName, String property, String value) {
|
||||
|
||||
BeanDefinition bd = factory.getBeanDefinition(beanName);
|
||||
while (bd.getOriginatingBeanDefinition() != null) {
|
||||
bd = bd.getOriginatingBeanDefinition();
|
||||
}
|
||||
bd.getPropertyValues().addPropertyValue(property, value);
|
||||
PropertyValue pv = new PropertyValue(property, value);
|
||||
pv.setOptional(this.ignoreInvalidKeys);
|
||||
bd.getPropertyValues().addPropertyValue(pv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user