Package io.micronaut.context
Interface BeanLocator
- All Known Subinterfaces:
ApplicationContext,BeanContext,BeanResolutionContext,ConditionContext<T>,ConfigurableApplicationContext,ConfigurableBeanContext
- All Known Implementing Classes:
AbstractBeanResolutionContext,DefaultBeanContext,DefaultBeanResolutionContext
public interface BeanLocator
Core interface for locating and discovering Bean instances.
- Since:
- 1.0
- Author:
- Graeme Rocher
-
Method Summary
Modifier and TypeMethodDescriptiondefault <T> Optional<T> Finds a Bean for the given type and qualifier.<T> Optional<T> Finds a Bean for the given type and qualifier.default <T> Optional<T> Finds a Bean for the given type.<T> Optional<T> Finds a Bean for the given type and qualifier.default <T> Optional<T> findOrInstantiateBean(Class<T> beanType) Finds a Bean for the given type or attempts to instantiate the given instance.default <T> TObtains a Bean for the given type and qualifier.default <T> TObtains a Bean for the given type and qualifier.<T> TgetBean(BeanDefinition<T> definition) Obtains a Bean for the given bean definition.default <T> TObtains a Bean for the given type.<T> TObtains a Bean for the given type and qualifier.default <T> Collection<T> getBeansOfType(Argument<T> beanType) Get all beans of the given type.default <T> Collection<T> getBeansOfType(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Get all beans of the given type.<T> Collection<T> getBeansOfType(Class<T> beanType) Get all beans of the given type.<T> Collection<T> getBeansOfType(Class<T> beanType, @Nullable Qualifier<T> qualifier) Get all beans of the given type.default <T> BeanProvider<T> getProvider(Argument<T> beanType) Obtains aBeanProviderfor the given type and qualifier.default <T> BeanProvider<T> getProvider(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtains aBeanProviderfor the given type and qualifier.default <T> BeanProvider<T> getProvider(Class<T> beanType) Obtains aBeanProviderfor the given type and qualifier.default <T> BeanProvider<T> getProvider(Class<T> beanType, @Nullable Qualifier<T> qualifier) Obtains aBeanProviderfor the given type and qualifier.default <T> TgetProxyTargetBean(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Resolves the proxy target for a given bean type.<T> TgetProxyTargetBean(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.default <T> Stream<T> streamOfType(Argument<T> beanType) Obtain a stream of beans of the given type.default <T> Stream<T> streamOfType(Argument<T> beanType, @Nullable Qualifier<T> qualifier) Obtain a stream of beans of the given type.default <T> Stream<T> streamOfType(Class<T> beanType) Obtain a stream of beans of the given type.<T> Stream<T> streamOfType(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
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
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
Obtains aBeanProviderfor 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 aBeanProviderfor 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
Obtains aBeanProviderfor 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 aBeanProviderfor 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
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
Optionalthat 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
Optionalthat 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 typequalifier- The qualifier- Returns:
- An instance of
Optionalthat 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
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
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
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
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
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 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
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
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
Optionalthat is either empty or containing the specified bean - Throws:
NonUniqueBeanException- When multiple possible bean definitions exist for the given type
-
findOrInstantiateBean
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
Optionalthat 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
-