flowable/flowable-engine · error · IllegalStateException

CDI BeanManager cannot find an instance of requested type

Error message

CDI BeanManager cannot find an instance of requested type '${name}'

What it means

ProgrammaticBeanLookup.lookup(String name, BeanManager) throws IllegalStateException when bm.getBeans(name) returns an empty set — no CDI bean is registered under that EL-style name. The string-based lookup resolves beans by bean name, and the requested name matches nothing in the container.

Solutions

  1. Verify the bean's @Named value (or CDI name) and correct the lookup string to match exactly.
  2. Add @Named("name") (or the expected qualifier/name) to the target bean so getBeans(name) finds it.
  3. Ensure the bean's package is in a discovered bean archive (beans.xml / bean-discovery-mode).
  4. Prefer the type-based lookup(Class, bm) variant when a unique type exists, avoiding name string drift.

Example fix

// before
Object svc = ProgrammaticBeanLookup.lookup("taskService", bm); // no bean named taskService
// after
@Named("taskService")
public class TaskServiceProvider { ... }
Object svc = ProgrammaticBeanLookup.lookup("taskService", bm);
Defensive patterns

Strategy: validation

Validate before calling

if (bm.getBeans("myBeanName").isEmpty()) {
    throw new IllegalStateException("No @Named bean 'myBeanName' registered");
}
Object o = ProgrammaticBeanLookup.lookup("myBeanName", bm);

Type guard

boolean namedBeanExists(String name, BeanManager bm) {
    return !bm.getBeans(name).isEmpty();
}

Try / catch

try {
    o = ProgrammaticBeanLookup.lookup("myBeanName", bm);
} catch (IllegalStateException e) {
    o = fallbackInstance; // application-provided default
}

Prevention

When it happens

Trigger: Calling ProgrammaticBeanLookup.lookup("someBeanName", beanManager) where the name doesn't match any @Named bean or CDI-registered bean name (typos, missing @Named annotation, bean archive not scanned).

Common situations: Renaming a @Named bean without updating lookup strings; bean archive not discovered (missing beans.xml); lookup string casing mismatch; bean removed in a version upgrade of flowable-cdi.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


AI-assisted analysis of flowable/flowable-engine@d6d39ce1c6 (2026-09-11). Data as JSON: /api/errors/35db72447e55d298. Report an issue: GitHub.

Appendix: source

Thrown at modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/util/ProgrammaticBeanLookup.java:46

public class ProgrammaticBeanLookup {

    @SuppressWarnings("unchecked")
    public static <T> T lookup(Class<T> clazz, BeanManager bm) {
        Iterator<Bean<?>> iter = bm.getBeans(clazz).iterator();
        if (!iter.hasNext()) {
            throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type " + clazz.getName());
        }
        Bean<T> bean = (Bean<T>) iter.next();
        CreationalContext<T> ctx = bm.createCreationalContext(bean);
        T dao = (T) bm.getReference(bean, clazz, ctx);
        return dao;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public static Object lookup(String name, BeanManager bm) {
        Set<Bean<?>> beans = bm.getBeans(name);
        if (beans.isEmpty()) {
            throw new IllegalStateException("CDI BeanManager cannot find an instance of requested type '" + name + "'");
        }
        Bean bean = bm.resolve(beans);
        CreationalContext ctx = bm.createCreationalContext(bean);
        // select one beantype randomly. A bean has a non-empty set of
        // beantypes.
        Type type = (Type) bean.getTypes().iterator().next();
        return bm.getReference(bean, type, ctx);
    }

    public static <T> T lookup(Class<T> clazz) {
        BeanManager bm = BeanManagerLookup.getBeanManager();
        return lookup(clazz, bm);
    }

    public static Object lookup(String name) {
        BeanManager bm = BeanManagerLookup.getBeanManager();
        return lookup(name, bm);
    }

View on GitHub (pinned to d6d39ce1c6)