Package io.micronaut.context
Interface BeanLocator
- All Known Subinterfaces:
ApplicationContext
,BeanContext
,ConditionContext<T>
,ConfigurableApplicationContext
,ConfigurableBeanContext
,InitializableBeanContext
- All Known Implementing Classes:
DefaultApplicationContext
,DefaultBeanContext
public interface BeanLocator
Core interface for locating and discovering Bean
instances.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Method Summary
Modifier and TypeMethodDescriptionFinds a Bean for the given type and qualifier.Finds a Bean for the given type and qualifier.Finds a Bean for the given type.Finds a Bean for the given type and qualifier.findOrInstantiateBean
(@NonNull Class<T> beanType) Finds a Bean for the given type or attempts to instantiate the given instance.default <T> T
Obtains a Bean for the given type and qualifier.default <T> T
Obtains a Bean for the given type and qualifier.<T> T
getBean
(@NonNull BeanDefinition<T> definition) Obtains a Bean for the given bean definition.default <T> T
Obtains a Bean for the given type.<T> T
Obtains a Bean for the given type and qualifier.default <T> @NonNull Collection<T>
getBeansOfType
(@NonNull Argument<T> beanType) Get all beans of the given type.default <T> @NonNull Collection<T>
getBeansOfType
(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Get all beans of the given type.<T> @NonNull Collection<T>
getBeansOfType
(@NonNull Class<T> beanType) Get all beans of the given type.<T> @NonNull Collection<T>
getBeansOfType
(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier) Get all beans of the given type.default <T> @NonNull BeanProvider<T>
getProvider
(@NonNull Argument<T> beanType) Obtains aBeanProvider
for the given type and qualifier.default <T> @NonNull BeanProvider<T>
getProvider
(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtains aBeanProvider
for the given type and qualifier.default <T> @NonNull BeanProvider<T>
getProvider
(@NonNull Class<T> beanType) Obtains aBeanProvider
for the given type and qualifier.default <T> @NonNull BeanProvider<T>
getProvider
(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtains aBeanProvider
for the given type and qualifier.default <T> T
getProxyTargetBean
(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Resolves the proxy target for a given bean type.<T> T
getProxyTargetBean
(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier) Resolves the proxy target for a given bean type.Obtain a map of beans of the given type where the key is the qualifier.Obtain a map of beans of the given type where the key is the qualifier.Obtain a map of beans of the given type where the key is the qualifier.Obtain a map of beans of the given type where the key is the qualifier.streamOfType
(@NonNull Argument<T> beanType) Obtain a stream of beans of the given type.streamOfType
(@NonNull Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain a stream of beans of the given type.streamOfType
(@NonNull Class<T> beanType) Obtain a stream of beans of the given type.streamOfType
(@NonNull Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtain a stream of beans of the given type.
-
Method Details
-
getBean
Obtains a Bean for the given bean definition.- Type Parameters:
T
- The bean type parameter- Parameters:
definition
- The bean type- Returns:
- An instanceof said bean
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- See Also:
-
getBean
@NonNull <T> T getBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtains a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instanceof said bean
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- See Also:
-
getBean
@NonNull default <T> T getBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtains a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- An instanceof said bean
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
- See Also:
-
getBean
Obtains a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potentially parameterized bean type- Returns:
- An instanceof said bean
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
- See Also:
-
getProvider
@NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtains aBeanProvider
for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The provider
- Since:
- 4.5.0
- See Also:
-
getProvider
Obtains aBeanProvider
for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- The provider
- Since:
- 4.5.0
- See Also:
-
getProvider
@NonNull default <T> @NonNull BeanProvider<T> getProvider(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtains aBeanProvider
for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- The provider
- Since:
- 4.5.0
- See Also:
-
getProvider
Obtains aBeanProvider
for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potentially parameterized bean type- Returns:
- A provider for the given type
- Since:
- 4.5.0
- See Also:
-
findBean
@NonNull <T> @NonNull Optional<T> findBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Finds a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
- See Also:
-
findBean
Finds a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- Since:
- 3.0.0
- See Also:
-
findBean
@NonNull <T> @NonNull Optional<T> findBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Finds a Bean for the given type and qualifier.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type- See Also:
-
getBeansOfType
Get all beans of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- The found beans
-
getBeansOfType
@NonNull <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Get all beans of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- The found beans
-
getBeansOfType
Get all beans of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potenitally parameterized bean type- Returns:
- The found beans
- Since:
- 3.0.0
-
getBeansOfType
@NonNull default <T> @NonNull Collection<T> getBeansOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Get all beans of the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The potenitally parameterized bean typequalifier
- The qualifier- Returns:
- The found beans
- Since:
- 3.0.0
-
streamOfType
@NonNull <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtain a stream of beans of the given type.- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The bean typequalifier
- The qualifier- Returns:
- A stream of instances
- See Also:
-
streamOfType
@NonNull default <T> @NonNull Stream<T> streamOfType(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Obtain a stream of beans of the given type.- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- A stream of instances
- Since:
- 3.0.0
- See Also:
-
streamOfType
Obtain a stream of beans of the given type.- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean type- Returns:
- A stream of instances
- Since:
- 3.0.0
- See Also:
-
mapOfType
@NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Argument<V> beanType, @Nullable @Nullable Qualifier<V> qualifier) Obtain a map of beans of the given type where the key is the qualifier.- Type Parameters:
V
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- A map of instances
- Since:
- 4.0.0
- See Also:
-
mapOfType
@NonNull default <V> @NonNull Map<String,V> mapOfType(@NonNull @NonNull Class<V> beanType, @Nullable @Nullable Qualifier<V> qualifier) Obtain a map of beans of the given type where the key is the qualifier.- Type Parameters:
V
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean typequalifier
- The qualifier- Returns:
- A map of instances
- Since:
- 4.0.0
- See Also:
-
mapOfType
Obtain a map of beans of the given type where the key is the qualifier.- Type Parameters:
V
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean type- Returns:
- A map of instances
- Since:
- 4.0.0
- See Also:
-
mapOfType
Obtain a map of beans of the given type where the key is the qualifier.- Type Parameters:
V
- The bean concrete type- Parameters:
beanType
- The potentially parameterized bean type- Returns:
- A map of instances
- Since:
- 4.0.0
- See Also:
-
getProxyTargetBean
@NonNull <T> T getProxyTargetBean(@NonNull @NonNull Class<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.- Type Parameters:
T
- The generic type- Parameters:
beanType
- The bean typequalifier
- The bean qualifier- Returns:
- The proxied instance
-
getProxyTargetBean
@NonNull default <T> T getProxyTargetBean(@NonNull @NonNull Argument<T> beanType, @Nullable @Nullable Qualifier<T> qualifier) Resolves the proxy target for a given bean type. If the bean has no proxy then the original bean is returned.- Type Parameters:
T
- The generic type- Parameters:
beanType
- The bean typequalifier
- The bean qualifier- Returns:
- The proxied instance
- Since:
- 3.0.0
-
streamOfType
Obtain a stream of beans of the given type.- Type Parameters:
T
- The bean concrete type- Parameters:
beanType
- The bean type- Returns:
- A stream
-
getBean
Obtains a Bean for the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- An instanceof said bean
- Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given typeNoSuchBeanException
- If the bean doesn't exist
-
findBean
Finds a Bean for the given type.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- An instance of
Optional
that is either empty or containing the specified bean - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-
findOrInstantiateBean
@NonNull default <T> @NonNull Optional<T> findOrInstantiateBean(@NonNull @NonNull Class<T> beanType) Finds a Bean for the given type or attempts to instantiate the given instance.- Type Parameters:
T
- The bean type parameter- Parameters:
beanType
- The bean type- Returns:
- An instance of
Optional
that is either empty or containing the specified bean if it could not be found or instantiated - Throws:
NonUniqueBeanException
- When multiple possible bean definitions exist for the given type
-