Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
爱吃血肠
spring-framework
提交
55011e7a
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,体验更适合开发者的 AI 搜索 >>
提交
55011e7a
编写于
11月 13, 2019
作者:
J
Juergen Hoeller
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Note on injecting results from local @Bean methods (self references)
Closes gh-23934
上级
2c1afca9
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
23 addition
and
10 deletion
+23
-10
src/docs/asciidoc/core/core-beans.adoc
src/docs/asciidoc/core/core-beans.adoc
+23
-10
未找到文件。
src/docs/asciidoc/core/core-beans.adoc
浏览文件 @
55011e7a
...
...
@@ -5428,6 +5428,7 @@ If there is no other resolution indicator (such as a qualifier or a primary mark
for
a
non
-
unique
dependency
situation
,
Spring
matches
the
injection
point
name
(
that
is
,
the
field
name
or
parameter
name
)
against
the
target
bean
names
and
choose
the
same
-
named
candidate
,
if
any
.
====
That
said
,
if
you
intend
to
express
annotation
-
driven
injection
by
name
,
do
not
primarily
use
`@
Autowired
`,
even
if
it
is
capable
of
selecting
by
bean
name
among
...
...
@@ -5451,16 +5452,28 @@ back to the bean that is currently injected). Note that self injection is a fall
Regular dependencies on other components always have precedence. In that sense, self
references do not participate in regular candidate selection and are therefore in
particular never primary. On the contrary, they always end up as lowest precedence.
In practice, you should use self references as a last resort only (for example, for calling other methods
on the same instance through the bean'
s
transactional
proxy
).
Consider
factoring
out
the
effected
methods
to
a
separate
delegate
bean
in
such
a
scenario
.
Alternatively
,
you
can
use
`@
Resource
`,
which
may
obtain
a
proxy
back
to
the
current
bean
by
its
unique
name
.
In practice, you should use self references as a last resort only (for example, for
calling other methods on the same instance through the bean'
s
transactional
proxy
).
Consider
factoring
out
the
effected
methods
to
a
separate
delegate
bean
in
such
a
scenario
.
Alternatively
,
you
can
use
`@
Resource
`,
which
may
obtain
a
proxy
back
to
the
current
bean
by
its
unique
name
.
[
NOTE
]
====
Trying
to
inject
the
results
from
`@
Bean
`
methods
on
the
same
configuration
class
is
effectively
a
self
-
reference
scenario
as
well
.
Either
lazily
resolve
such
references
in
the
method
signature
where
it
is
actually
needed
(
as
opposed
to
an
autowired
field
in
the
configuration
class
)
or
declare
the
affected
`@
Bean
`
methods
as
`
static
`,
decoupling
them
from
the
containing
configuration
class
instance
and
its
lifecycle
.
Otherwise
,
such
beans
are
only
considered
in
the
fallback
phase
,
with
matching
beans
on
other
configuration
classes
selected
as
primary
candidates
instead
(
if
available
).
====
`@
Autowired
`
applies
to
fields
,
constructors
,
and
multi
-
argument
methods
,
allowing
for
narrowing
through
qualifier
annotations
at
the
parameter
level
.
In
contrast
,
`@
Resource
`
is
supported
only
for
fields
and
bean
property
setter
methods
with
a
single
argument
.
As
a
consequence
,
you
should
stick
with
qualifiers
if
your
injection
target
is
a
constructor
or
a
multi
-
argument
method
.
As
a
consequence
,
you
should
stick
with
qualifiers
if
your
injection
target
is
a
constructor
or
a
multi
-
argument
method
.
You
can
create
your
own
custom
qualifier
annotations
.
To
do
so
,
define
an
annotation
and
provide
the
`@
Qualifier
`
annotation
within
your
definition
,
as
the
following
example
shows
:
...
...
@@ -6849,12 +6862,12 @@ constraints applying.
====
You may declare `@Bean` methods as `static`, allowing for them to be called without
creating their containing configuration class as an instance. This makes particular
sense when defining post-processor beans (for example, of type `BeanFactoryPostProcessor`
or
`BeanPostProcessor`), since such beans get initialized early in the container
sense when defining post-processor beans (for example, of type `BeanFactoryPostProcessor`
or
`BeanPostProcessor`), since such beans get initialized early in the container
lifecycle and should avoid triggering other parts of the configuration at that point.
Calls to static `@Bean` methods never get intercepted by the container,
not even within
`@Configuration` classes (as described earlier in this section), due to technical
Calls to static `@Bean` methods never get intercepted by the container,
not even within
`@Configuration` classes (as described earlier in this section), due to technical
limitations: CGLIB subclassing can override only non-static methods. As a consequence,
a direct call to another `@Bean` method has standard Java semantics, resulting
in an independent instance being returned straight from the factory method itself.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录