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 ${clazz.getName()} What it means
ProgrammaticBeanLookup.lookup(Class<T>, BeanManager) throws IllegalStateException when bm.getBeans(clazz) returns no bean of the requested type — the CDI container has no eligible bean matching the class. This happens during programmatic lookup of engine services (e.g. Manager instance lookup) when the required bean is not in the deployed CDI archive.
Solutions
- Ensure the requested type is an available CDI bean (add a @Produces or a managed bean definition for it).
- Include the package in bean discovery (beans.xml bean-discovery-mode="all" or annotated with proper scope annotations).
- Check classpath: the flowable-cdi module's beans must be in a bean archive visible to the CDI container.
- Lookup by a type that is actually registered (e.g. the interface with a producer) instead of the concrete class.
Example fix
// before
MyService s = ProgrammaticBeanLookup.lookup(MyService.class, bm); // no bean
// after: define a producer
@Produces public MyService produce() { return new MyServiceImpl(); } Defensive patterns
Strategy: validation
Validate before calling
if (bm.getBeans(MyService.class).isEmpty()) {
throw new IllegalStateException("Register a CDI bean/producer for MyService before lookup");
}
MyService s = ProgrammaticBeanLookup.lookup(MyService.class, bm); Type guard
boolean beanOfTypeExists(Class<?> clazz, BeanManager bm) {
return !bm.getBeans(clazz).isEmpty();
} Try / catch
try {
s = ProgrammaticBeanLookup.lookup(MyService.class, bm);
} catch (IllegalStateException e) {
s = new MyServiceImpl(); // local default instead of CDI-managed
} Prevention
- Verify the target type has a scope annotation or @Produces before programmatic lookup.
- Keep flowable-cdi packages inside a discovered bean archive (beans.xml / discovery mode).
- Lookup interfaces that actually have producers rather than concrete classes.
- Add a container bootstrap test that resolves all programmatically looked-up beans.
When it happens
Trigger: Calling ProgrammaticBeanLookup.lookup(SomeClass.class, beanManager) where no bean with that type exists — missing @Injectable/producer, class not annotated as a bean, or the class isn't in a bean archive discovered by CDI.
Common situations: beans.xml/bean-discovery-mode excludes the package; flowable-cdi beans not on the classpath; missing producer method for an interface type; lookup by concrete class when only an interface is exposed.
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/a95ff89bff4292a9.
Report an issue: GitHub.
Appendix: source
Thrown at modules/flowable-cdi/src/main/java/org/flowable/cdi/impl/util/ProgrammaticBeanLookup.java:34
import java.util.Iterator;
import java.util.Set;
import jakarta.enterprise.context.spi.CreationalContext;
import jakarta.enterprise.inject.spi.Bean;
import jakarta.enterprise.inject.spi.BeanManager;
/**
* Utility class for performing programmatic bean lookups.
*
* @author Daniel Meyer
*/
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();
View on GitHub (pinned to d6d39ce1c6)