@Typed public final class BeanProvider extends Object
This class contains utility methods to resolve contextual references in situations where no injection is available because the current class is not managed by the CDI Container. This can happen in e.g. a JPA-2.0 EntityListener, a ServletFilter, a Spring managed Bean, etc.
Attention: This method is intended for being used in user code at runtime. If this method gets used during Container boot (in an Extension), non-portable behaviour results. The CDI specification only allows injection of the BeanManager during CDI-Container boot time.
BeanManagerProvider
Modifier and Type | Method and Description |
---|---|
static <T> T |
getContextualReference(javax.enterprise.inject.spi.BeanManager beanManager,
Class<T> type,
boolean optional,
Annotation... qualifiers)
#getContextualReference(Class, Annotation...) which returns null if the
'optional' parameter is set to true . |
public static <T> T getContextualReference(javax.enterprise.inject.spi.BeanManager beanManager, Class<T> type, boolean optional, Annotation... qualifiers)
#getContextualReference(Class, Annotation...)
which returns null
if the
'optional' parameter is set to true
.
This method is intended for usage where the BeanManger is known, e.g. in Extensions.T
- target typebeanManager
- the BeanManager to usetype
- the type of the bean in questionoptional
- if true
it will return null
if no bean could be found or created.
Otherwise it will throw an IllegalStateException
qualifiers
- additional qualifiers which further distinct the resolved bean#getContextualReference(Class, Annotation...)
Copyright © 2020 The Apache Software Foundation. All rights reserved.