Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
240819f9
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,发现更多精彩内容 >>
提交
240819f9
编写于
1月 03, 2014
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Introduced "spring.beaninfo.ignore" system property for optimized Introspector usage
Issue: SPR-9014 (cherry picked from commit
f88cbda6
)
上级
8d1e55d1
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
54 addition
and
3 deletion
+54
-3
spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
...org/springframework/beans/CachedIntrospectionResults.java
+54
-3
未找到文件。
spring-beans/src/main/java/org/springframework/beans/CachedIntrospectionResults.java
浏览文件 @
240819f9
...
...
@@ -52,6 +52,18 @@ import org.springframework.util.StringUtils;
* implements the factory design pattern, using a private constructor and
* a static {@link #forClass(Class)} factory method to obtain instances.
*
* <p>Note that for caching to work effectively, some preconditions need to be met:
* Prefer an arrangement where the Spring jars live in the same ClassLoader as the
* application classes, which allows for clean caching along with the application's
* lifecycle in any case. For a web application, consider declaring a local
* {@link org.springframework.web.util.IntrospectorCleanupListener} in {@code web.xml}
* in case of a multi-ClassLoader layout, which will allow for effective caching as well.
*
* <p>In case of a non-clean ClassLoader arrangement without a cleanup listener having
* been set up, this class will fall back to a weak-reference-based caching model that
* recreates much-requested entries every time the garbage collector removed them. In
* such a scenario, consider the {@link #IGNORE_BEANINFO_PROPERTY_NAME} system property.
*
* @author Rod Johnson
* @author Juergen Hoeller
* @since 05 May 2001
...
...
@@ -61,11 +73,33 @@ import org.springframework.util.StringUtils;
*/
public
class
CachedIntrospectionResults
{
/**
* System property that instructs Spring to use the {@link Introspector#IGNORE_ALL_BEANINFO}
* mode when calling the JavaBeans {@link Introspector}: "spring.beaninfo.ignore", with a
* value of "true" skipping the search for {@code BeanInfo} classes (typically for scenarios
* where no such classes are being defined for beans in the application in the first place).
* <p>Default is "false", considering all {@code BeanInfo} metadata classes, like for
* standard {@link Introspector#getBeanInfo(Class)} calls. Consider switching this flag to
* "true" if you experience repeated ClassLoader access for non-existing {@code BeanInfo}
* classes, in case such access is expensive on startup or on lazy loading.
* <p>Note that such an effect may also indicate a scenario where caching doesn't work
* effectively: Prefer an arrangement where the Spring jars live in the same ClassLoader
* as the application classes, which allows for clean caching along with the application's
* lifecycle in any case. For a web application, consider declaring a local
* {@link org.springframework.web.util.IntrospectorCleanupListener} in {@code web.xml}
* in case of a multi-ClassLoader layout, which will allow for effective caching as well.
* @see Introspector#getBeanInfo(Class, int)
*/
public
static
final
String
IGNORE_BEANINFO_PROPERTY_NAME
=
"spring.beaninfo.ignore"
;
private
static
final
Log
logger
=
LogFactory
.
getLog
(
CachedIntrospectionResults
.
class
);
private
static
final
boolean
shouldIntrospectorIgnoreBeaninfoClasses
;
/** Stores the BeanInfoFactory instances */
private
static
List
<
BeanInfoFactory
>
beanInfoFactories
=
SpringFactoriesLoader
.
loadFactories
(
BeanInfoFactory
.
class
,
CachedIntrospectionResults
.
class
.
getClassLoader
());
private
static
List
<
BeanInfoFactory
>
beanInfoFactories
=
SpringFactoriesLoader
.
loadFactories
(
BeanInfoFactory
.
class
,
CachedIntrospectionResults
.
class
.
getClassLoader
());
/**
* Set of ClassLoaders that this CachedIntrospectionResults class will always
...
...
@@ -81,6 +115,21 @@ public class CachedIntrospectionResults {
static
final
Map
<
Class
<?>,
Object
>
classCache
=
new
WeakHashMap
<
Class
<?>,
Object
>();
static
{
boolean
ignoreValue
;
try
{
ignoreValue
=
"true"
.
equalsIgnoreCase
(
System
.
getProperty
(
IGNORE_BEANINFO_PROPERTY_NAME
));
}
catch
(
Throwable
ex
)
{
if
(
logger
.
isDebugEnabled
())
{
logger
.
debug
(
"Could not obtain system property '"
+
IGNORE_BEANINFO_PROPERTY_NAME
+
"': "
+
ex
);
}
ignoreValue
=
false
;
}
shouldIntrospectorIgnoreBeaninfoClasses
=
ignoreValue
;
}
/**
* Accept the given ClassLoader as cache-safe, even if its classes would
* not qualify as cache-safe in this CachedIntrospectionResults class.
...
...
@@ -243,7 +292,9 @@ public class CachedIntrospectionResults {
}
if
(
beanInfo
==
null
)
{
// If none of the factories supported the class, fall back to the default
beanInfo
=
Introspector
.
getBeanInfo
(
beanClass
);
beanInfo
=
(
shouldIntrospectorIgnoreBeaninfoClasses
?
Introspector
.
getBeanInfo
(
beanClass
,
Introspector
.
IGNORE_ALL_BEANINFO
)
:
Introspector
.
getBeanInfo
(
beanClass
));
}
this
.
beanInfo
=
beanInfo
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录