Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
.-Smile-.
spring-framework
提交
4eea675c
S
spring-framework
项目概览
.-Smile-.
/
spring-framework
与 Fork 源项目一致
从无法访问的项目Fork
通知
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,发现更多精彩内容 >>
提交
4eea675c
编写于
6月 11, 2015
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Stronger warning about lookup methods not working with @Bean
Issue: SPR-13108
上级
e97506be
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
21 addition
and
16 deletion
+21
-16
spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java
.../org/springframework/beans/factory/annotation/Lookup.java
+9
-6
src/asciidoc/core-beans.adoc
src/asciidoc/core-beans.adoc
+12
-10
未找到文件。
spring-beans/src/main/java/org/springframework/beans/factory/annotation/Lookup.java
浏览文件 @
4eea675c
/*
* Copyright 2002-201
4
the original author or authors.
* Copyright 2002-201
5
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.
...
...
@@ -38,12 +38,15 @@ import java.lang.annotation.Target;
* container to fill them in at runtime. In both cases, the container will generate
* runtime subclasses of the method's containing class via CGLIB, which is why such
* lookup methods can only work on beans that the container instantiates through
* regular constructors
(
i.e. lookup methods cannot get replaced on beans returned
* from factory methods where we can
't dynamically provide a subclass for them)
.
* regular constructors
:
i.e. lookup methods cannot get replaced on beans returned
* from factory methods where we can
not dynamically provide a subclass for them
.
*
* <p>Note: When used with component scanning or any other mechanism that filters
* out abstract beans, provide stub implementations of your lookup methods to be
* able to declare them as concrete classes.
* <p><b>Concrete limitations in typical Spring configuration scenarios:</b>
* When used with component scanning or any other mechanism that filters out abstract
* beans, provide stub implementations of your lookup methods to be able to declare
* them as concrete classes. And please remember that lookup methods won't work on
* beans returned from {@code @Bean} methods in configuration classes; you'll have
* to resort to {@code @Inject Provider<TargetBean>} or the like instead.
*
* @author Juergen Hoeller
* @since 4.1
...
...
src/asciidoc/core-beans.adoc
浏览文件 @
4eea675c
...
...
@@ -2032,15 +2032,17 @@ overrides the method.
[NOTE]
====
For this dynamic subclassing to work, the class that the Spring container will subclass
cannot be `final`, and the method to be overridden cannot be `final` either. Also,
testing a class that has an `abstract` method requires you to subclass the class
yourself and to supply a stub implementation of the `abstract` method. Finally, objects
that have been the target of method injection cannot be serialized. As of Spring 3.2 it
is no longer necessary to add CGLIB to your classpath, because CGLIB classes are
repackaged under org.springframework and distributed within the spring-core JAR. This is
done both for convenience as well as to avoid potential conflicts with other projects
that use differing versions of CGLIB.
* For this dynamic subclassing to work, the class that the Spring bean container will
subclass cannot be `final`, and the method to be overridden cannot be `final` either.
* Unit-testing a class that has an `abstract` method requires you to subclass the class
yourself and to supply a stub implementation of the `abstract` method.
* Concrete methods are also necessary for component scanning which requires concrete
classes to pick up.
* A further key limitation is that lookup methods won'
t
work
with
factory
methods
and
in
particular
not
with
`@
Bean
`
methods
in
configuration
classes
,
since
the
container
is
not
in
charge
of
creating
the
instance
in
that
case
and
therefore
cannot
create
a
runtime
-
generated
subclass
on
the
fly
.
*
Finally
,
objects
that
have
been
the
target
of
method
injection
cannot
be
serialized
.
====
Looking
at
the
`
CommandManager
`
class
in
the
previous
code
snippet
,
you
see
that
the
...
...
@@ -2116,7 +2118,7 @@ these classes for additional information.
[[
beans
-
factory
-
arbitrary
-
method
-
replacement
]]
====
Arbitrary
method
replacement
A less useful form of method injection than lookup method
I
njection is the ability to
A
less
useful
form
of
method
injection
than
lookup
method
i
njection
is
the
ability
to
replace
arbitrary
methods
in
a
managed
bean
with
another
method
implementation
.
Users
may
safely
skip
the
rest
of
this
section
until
the
functionality
is
actually
needed
.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录