Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
ad492e90
S
spring-framework
项目概览
爱吃血肠
/
spring-framework
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
S
spring-framework
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
ad492e90
编写于
9月 24, 2009
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
PropertyOverrideConfigurer's "ignoreInvalidKeys" ignores invalid property names as well (SPR-5792)
上级
557dd1f1
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
12 deletion
+37
-12
org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
.../main/java/org/springframework/beans/BeanWrapperImpl.java
+11
-4
org.springframework.beans/src/main/java/org/springframework/beans/PropertyValue.java
...rc/main/java/org/springframework/beans/PropertyValue.java
+12
-0
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java
...work/beans/factory/config/PropertyOverrideConfigurer.java
+9
-6
org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java
...beans/factory/config/PropertyResourceConfigurerTests.java
+5
-2
未找到文件。
org.springframework.beans/src/main/java/org/springframework/beans/BeanWrapperImpl.java
浏览文件 @
ad492e90
...
...
@@ -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
;
}
...
...
org.springframework.beans/src/main/java/org/springframework/beans/PropertyValue.java
浏览文件 @
ad492e90
...
...
@@ -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>).
...
...
org.springframework.beans/src/main/java/org/springframework/beans/factory/config/PropertyOverrideConfigurer.java
浏览文件 @
ad492e90
/*
* Copyright 2002-200
8
the original author or authors.
* Copyright 2002-200
9
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
);
}
...
...
org.springframework.beans/src/test/java/org/springframework/beans/factory/config/PropertyResourceConfigurerTests.java
浏览文件 @
ad492e90
...
...
@@ -25,7 +25,6 @@ import java.util.prefs.Preferences;
import
static
org
.
junit
.
Assert
.*;
import
org.junit.Before
;
import
org.junit.Ignore
;
import
org.junit.Test
;
import
test.beans.IndexedTestBean
;
import
test.beans.TestBean
;
...
...
@@ -281,8 +280,11 @@ public final class PropertyResourceConfigurerTests {
Properties
props
=
new
Properties
();
props
.
setProperty
(
"argh"
,
"hgra"
);
props
.
setProperty
(
"tb2.name"
,
"test"
);
props
.
setProperty
(
"tb2.nam"
,
"test"
);
props
.
setProperty
(
"tb3.name"
,
"test"
);
poc
.
setProperties
(
props
);
poc
.
postProcessBeanFactory
(
factory
);
assertEquals
(
"test"
,
factory
.
getBean
(
"tb2"
,
TestBean
.
class
).
getName
());
}
{
PropertyOverrideConfigurer
poc
=
new
PropertyOverrideConfigurer
();
...
...
@@ -294,7 +296,8 @@ public final class PropertyResourceConfigurerTests {
poc
.
setOrder
(
0
);
// won't actually do anything since we're not processing through an app ctx
try
{
poc
.
postProcessBeanFactory
(
factory
);
}
catch
(
BeanInitializationException
ex
)
{
}
catch
(
BeanInitializationException
ex
)
{
// prove that the processor chokes on the invalid key
assertTrue
(
ex
.
getMessage
().
toLowerCase
().
contains
(
"argh"
));
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录