javax.enterprise.inject.AmbiguousResolutionException Java Examples

The following examples show how to use javax.enterprise.inject.AmbiguousResolutionException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CDIBeanResolver.java    From trimou with Apache License 2.0 6 votes vote down vote up
@Override
public void init() {
    if (beanManager == null) {
        throw new IllegalStateException("BeanManager not set - invalid resolver configuration");
    }
    // Init cache max size
    long beanCacheMaxSize = configuration.getLongPropertyValue(BEAN_CACHE_MAX_SIZE_KEY);
    beanCache = configuration.getComputingCacheFactory().create(COMPUTING_CACHE_CONSUMER_ID, key -> {
        Set<Bean<?>> beans = beanManager.getBeans(key);
        // Check required for CDI 1.0
        if (beans == null || beans.isEmpty()) {
            return Optional.empty();
        }
        try {
            return Optional.of(beanManager.resolve(beans));
        } catch (AmbiguousResolutionException e) {
            LOGGER.warn("An ambiguous EL name exists [name: {}]", key);
            return Optional.empty();
        }
    }, null, beanCacheMaxSize, null);
    LOGGER.debug("Initialized [beanCacheMaxSize: {}]", beanCacheMaxSize);
}
 
Example #2
Source File: InstanceImpl.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
private InjectableBean<T> bean() {
    Set<InjectableBean<?>> beans = beans();
    if (beans.isEmpty()) {
        throw new UnsatisfiedResolutionException(
                "No bean found for required type [" + requiredType + "] and qualifiers [" + requiredQualifiers + "]");
    } else if (beans.size() > 1) {
        throw new AmbiguousResolutionException("Beans: " + beans.toString());
    }
    return (InjectableBean<T>) beans.iterator().next();
}