|
|
|
@ -6417,10 +6417,28 @@ attribute to specify beans by type, or `name` to specify beans by name. The `sea
|
|
|
|
|
attribute allows you to limit the `ApplicationContext` hierarchy that should be considered
|
|
|
|
|
when searching for beans.
|
|
|
|
|
|
|
|
|
|
When placed on a `@Bean` method, the target type defaults to the return type of the
|
|
|
|
|
method, for instance:
|
|
|
|
|
|
|
|
|
|
[source,java,indent=0]
|
|
|
|
|
----
|
|
|
|
|
@Configuration
|
|
|
|
|
public class MyAutoConfiguration {
|
|
|
|
|
|
|
|
|
|
@Bean
|
|
|
|
|
@ConditionalOnMissingBean
|
|
|
|
|
public MyService myService() { ... }
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
----
|
|
|
|
|
|
|
|
|
|
In the example above, the `myService` bean is going to be created if no bean of type
|
|
|
|
|
`MyService` is already contained in the `ApplicationContext`.
|
|
|
|
|
|
|
|
|
|
TIP: You need to be very careful about the order that bean definitions are added as these
|
|
|
|
|
conditions are evaluated based on what has been processed so far. For this reason,
|
|
|
|
|
we recommend only using `@ConditionalOnBean` and `@ConditionalOnMissingBean` annotations
|
|
|
|
|
on auto-configuration classes (since these are guaranteed to load after any user-define
|
|
|
|
|
on auto-configuration classes (since these are guaranteed to load after any user-defined
|
|
|
|
|
beans definitions have been added).
|
|
|
|
|
|
|
|
|
|
NOTE: `@ConditionalOnBean` and `@ConditionalOnMissingBean` do not prevent `@Configuration`
|
|
|
|
|