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
- Verify the bean's @Named value (or CDI name) and correct the lookup string to match exactly.
- Add @Named("name") (or the expected qualifier/name) to the target bean so getBeans(name) finds it.
- Ensure the bean's package is in a discovered bean archive (beans.xml / bean-discovery-mode).
- 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
- Annotate beans with @Named and match the lookup string exactly (case-sensitive).
- Prefer type-based lookup(Class, bm) to avoid name-string drift.
- Keep lookup names in constants next to the bean definition to avoid rename mismatch.
- Ensure the bean's archive is included in CDI bean discovery.
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
- CDI BeanManager cannot find an instance of requested type
- Cannot associate execution by id: no execution with id '
- Cannot resume task with id '
- Cannot use startProcessByName in an active command.
- Cannot use this method of the BusinessProcess bean within…
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)