本文整理了Java中javax.enterprise.inject.spi.CDI.current()
方法的一些代码示例,展示了CDI.current()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CDI.current()
方法的具体详情如下:
包路径:javax.enterprise.inject.spi.CDI
类名称:CDI
方法名:current
[英]Get the CDI instance that provides access to the current container.
If there are no providers available, an IllegalStateException is thrown, otherwise the first provider which can access the container is used.
[中]获取提供对当前容器的访问的CDI实例。
如果没有可用的提供程序,将抛出IllegalStateException,否则将使用第一个可以访问容器的提供程序。
代码示例来源:origin: javax.enterprise/cdi-api
/**
* Create an injector for the given class, using the current bean manager
* @param clazz class of the unmanaged instances
*/
public Unmanaged(Class<T> clazz) {
this(CDI.current().getBeanManager(), clazz);
}
代码示例来源:origin: oracle/helidon
@Override
public BeanManager getBeanManager() {
if (beanManager == null) {
CDI<Object> cdi = CDI.current();
if (cdi != null) {
beanManager = cdi.getBeanManager();
}
}
return beanManager;
}
代码示例来源:origin: oracle/helidon
static synchronized MetricRegistry getMetricRegistry() {
if (metricRegistry == null) {
metricRegistry = CDI.current().select(MetricRegistry.class).get();
}
return metricRegistry;
}
代码示例来源:origin: oracle/helidon
public RequestContextController getRequestContextController() {
if (requestContextController == null) {
CDI<Object> cdi = CDI.current();
if (cdi != null) {
requestContextController = cdi.select(RequestContextController.class).get();
}
}
return requestContextController;
}
}
代码示例来源:origin: javaee-samples/javaee7-samples
private void callCDIBean(HttpServletRequest request, HttpServletResponse response, String phase) {
try {
CDIBean cdiBean = CDI.current().select(CDIBean.class).get();
response.getWriter().write(phase + ": " + cdiBean.getText() + "\n");
cdiBean.setTextViaInjectedRequest();
response.getWriter().write(phase + ": " + request.getAttribute("text")+ "\n");
} catch (Exception e) {
logger.log(SEVERE, "", e);
}
}
代码示例来源:origin: oracle/helidon
private Optional<SeContainer> currentContainter() {
try {
CDI<Object> current = CDI.current();
STARTUP_LOGGER.finest("CDI.current()");
if (null == current) {
return Optional.empty();
}
if (current instanceof SeContainer) {
SeContainer currentSe = (SeContainer) current;
if (currentSe.isRunning()) {
return Optional.of(currentSe);
} else {
return Optional.empty();
}
} else {
throw new MpException("Running in a non-SE CDI Container: " + current.getClass().getName());
}
} catch (IllegalStateException e) {
return Optional.empty();
}
}
代码示例来源:origin: oracle/helidon
private Object getClaimValue(CreationalContext<Object> context) {
JsonWebTokenImpl token = CDI.current().select(JsonWebTokenImpl.class, new Impl() {
@Override
public Class<? extends Annotation> annotationType() {
return Impl.class;
}
}).get();
return getClaimValue(qualifier.name(), token, qualifier);
}
代码示例来源:origin: jersey/jersey
@Override
public BeanManager getBeanManager() {
InitialContext initialContext = null;
try {
initialContext = new InitialContext();
return (BeanManager) initialContext.lookup("java:comp/BeanManager");
} catch (final Exception ex) {
try {
return CDI.current().getBeanManager();
} catch (final Exception e) {
LOGGER.config(LocalizationMessages.CDI_BEAN_MANAGER_JNDI_LOOKUP_FAILED());
return null;
}
} finally {
if (initialContext != null) {
try {
initialContext.close();
} catch (final NamingException ignored) {
// no-op
}
}
}
}
}
代码示例来源:origin: HotswapProjects/HotswapAgent
if (CDI.current().getBeanManager() instanceof BeanManagerImpl) {
beanManager = ((BeanManagerImpl) CDI.current().getBeanManager()).unwrap();
} else {
beanManager = ((BeanManagerProxy) CDI.current().getBeanManager()).unwrap();
代码示例来源:origin: oracle/helidon
if (handlerClass != null) {
FallbackHandler<?> handler = CDI.current().select(handlerClass).get();
result = handler.handle(
new ExecutionContext() {
代码示例来源:origin: HotswapProjects/HotswapAgent
BeanManager bm = CDI.current().getBeanManager();
代码示例来源:origin: resteasy/Resteasy
public CdiRequestDispatcher(final SynchronousDispatcher dispatcher, final ResteasyProviderFactory providerFactory,
final SecurityDomain domain){
this(dispatcher, providerFactory, domain, CDI.current());
}
public CdiRequestDispatcher(final SynchronousDispatcher dispatcher, final ResteasyProviderFactory providerFactory,
代码示例来源:origin: HotswapProjects/HotswapAgent
BeanManager bm = CDI.current().getBeanManager();
代码示例来源:origin: resteasy/Resteasy
public CdiNettyJaxrsServer() {
this.instance = CDI.current();
}
public CdiNettyJaxrsServer(final Instance<Object> instance) {
代码示例来源:origin: resteasy/Resteasy
public static BeanManager lookupBeanManagerCDIUtil()
{
BeanManager bm = null;
try
{
bm = CDI.current().getBeanManager();
}
catch (NoClassDefFoundError e)
{
LogMessages.LOGGER.debug(Messages.MESSAGES.unableToFindCDIClass(), e);
}
catch (Exception e)
{
LogMessages.LOGGER.debug(Messages.MESSAGES.errorOccurredLookingUpViaCDIUtil(), e);
}
return bm;
}
代码示例来源:origin: javax/javaee-web-api
/**
* Create an injector for the given class, using the current bean manager
* @param clazz class of the unmanaged instances
*/
public Unmanaged(Class<T> clazz) {
this(CDI.current().getBeanManager(), clazz);
}
代码示例来源:origin: br.com.jarch/jarch-utils
@Deprecated
public static <T> T getInstanceReference(Class<T> clazz) {
// Bean<T> bean = (Bean<T>) beanManager.resolve(beanManager.getBeans(clazz));
// return beanManager.getContext(bean.getScope()).get(bean, beanManager.createCreationalContext(bean));
return CDI.current().select(clazz).get();
}
}
代码示例来源:origin: org.jboss.narayana.jts/narayana-jts-idlj
@Override
public final T create(final CreationalContext<T> cc) {
try {
return this.type.cast(CDI.current().select(InitialContext.class).get().lookup(this.name));
} catch (final NamingException namingException) {
throw new CreationException(namingException.getMessage(), namingException);
}
}
代码示例来源:origin: org.commonjava.cdi.util/weft
@PostConstruct
public void init()
{
try
{
this.metricRegistry = CDI.current().select( MetricRegistry.class).get();
}
catch ( UnsatisfiedResolutionException e )
{
logger.info( e.getMessage() );
}
}
代码示例来源:origin: org.apache.meecrowave/meecrowave-junit
private static CreationalContext<Object> doInject(final Object instance) {
final BeanManager bm = CDI.current().getBeanManager();
final AnnotatedType<?> annotatedType = bm.createAnnotatedType(instance.getClass());
final InjectionTarget injectionTarget = bm.createInjectionTarget(annotatedType);
final CreationalContext<Object> creationalContext = bm.createCreationalContext(null);
injectionTarget.inject(instance, creationalContext);
return creationalContext;
}
内容来源于网络,如有侵权,请联系作者删除!