{"record":{"id":"d184c6ab1e4356c6","repo":"flowable/flowable-engine","slug":"could-not-resolve-the-kafkalistenercontainerfactor","errorCode":null,"errorMessage":"Could not resolve the KafkaListenerContainerFactory to use for [<endpoint>] no factory was given and no default is set.","messagePattern":"Could not resolve the KafkaListenerContainerFactory to use for \\[<endpoint>\\] no factory was given and no default is set\\.","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/flowable-event-registry-spring/src/main/java/org/flowable/eventregistry/spring/kafka/KafkaChannelDefinitionProcessor.java","lineNumber":827,"sourceCode":"        // This also makes sure that we are not going to start our listener earlier than the KafkaListenerEndpointRegistry\n        boolean startImmediately = contextRefreshed || endpointRegistry.isRunning();\n        logger.info(\"Registering endpoint {}\", endpoint);\n        endpointRegistry.registerListenerContainer(endpoint, resolveContainerFactory(endpoint, factory), startImmediately);\n        logger.info(\"Finished registering endpoint {}\", endpoint);\n    }\n\n    protected KafkaListenerContainerFactory<?> resolveContainerFactory(KafkaListenerEndpoint endpoint, KafkaListenerContainerFactory<?> containerFactory) {\n        if (containerFactory != null) {\n            return containerFactory;\n        } else if (this.containerFactory != null) {\n            return this.containerFactory;\n        } else if (containerFactoryBeanName != null) {\n            Assert.state(beanFactory != null, \"BeanFactory must be set to obtain container factory by bean name\");\n            // Consider changing this if live change of the factory is required...\n            this.containerFactory = beanFactory.getBean(containerFactoryBeanName, KafkaListenerContainerFactory.class);\n            return this.containerFactory;\n        } else {\n            throw new IllegalStateException(\"Could not resolve the \" +\n                KafkaListenerContainerFactory.class.getSimpleName() + \" to use for [\" +\n                endpoint + \"] no factory was given and no default is set.\");\n        }\n    }\n\n    protected String getEndpointId(ChannelModel channelModel, String tenantId) {\n        String channelDefinitionKey = channelModel.getKey();\n        if (!StringUtils.hasText(tenantId)) {\n            return CHANNEL_ID_PREFIX + channelDefinitionKey;\n        }\n        return CHANNEL_ID_PREFIX + tenantId + \"#\" + channelDefinitionKey;\n    }\n\n    protected String getEndpointGroupId(KafkaInboundChannelModel channelDefinition, String id) {\n        String groupId = resolveExpressionAsString(channelDefinition.getGroupId(), \"groupId\");\n        if (groupId == null) {\n            groupId = id;\n        }","sourceCodeStart":809,"sourceCodeEnd":845,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable-event-registry-spring/src/main/java/org/flowable/eventregistry/spring/kafka/KafkaChannelDefinitionProcessor.java#L809-L845","documentation":"Modeled after Spring Kafka's KafkaListenerEndpointRegistrar: when no containerFactory was set directly and no containerFactoryBeanName is configured, the registrar cannot obtain a KafkaListenerContainerFactory for the endpoint and throws IllegalStateException. Every Kafka listener endpoint needs a container factory to create its MessageListenerContainer.","triggerScenarios":"Registering an inbound Kafka channel endpoint when neither the default container factory on the processor nor a containerFactoryBeanName is available (beanFactory also unset for name lookup).","commonSituations":"Missing KafkaListenerContainerFactory bean in the Spring context; channel model omitted the container factory reference; running outside a fully wired Spring application context.","solutions":["Define a ConcurrentKafkaListenerContainerFactory bean and let the processor pick it as default (set via KafkaChannelDefinitionProcessor#setContainerFactory).","Set the containerFactoryBeanName (e.g. \"kafkaListenerContainerFactory\") so it is looked up from the BeanFactory.","Ensure beanFactory is set on the registrar when resolving by name.","Add a spring-kafka annotation-driven configuration (@EnableKafka with default factory) to the application context."],"exampleFix":"// before\n// no factory bean defined\n// after\n@Bean\npublic ConcurrentKafkaListenerContainerFactory<String, String> kafkaListenerContainerFactory(ConsumerFactory<String, String> cf) {\n    ConcurrentKafkaListenerContainerFactory<String, String> f = new ConcurrentKafkaListenerContainerFactory<>();\n    f.setConsumerFactory(cf);\n    return f;\n}","handlingStrategy":"validation","validationCode":"if (applicationContext.getBeansOfType(KafkaListenerContainerFactory.class).isEmpty()\n        && !applicationContext.containsBean(\"kafkaListenerContainerFactory\")) {\n    throw new IllegalStateException(\"No KafkaListenerContainerFactory bean defined\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    deployChannel(channelModel);\n} catch (IllegalStateException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"no factory was given and no default is set\")) {\n        log.error(\"Define a KafkaListenerContainerFactory bean\", e);\n    } else { throw e; }\n}","preventionTips":["Always define a ConcurrentKafkaListenerContainerFactory bean when using Kafka inbound channels","Enable @EnableKafka with a default factory in the application context","Specify containerFactoryBeanName explicitly in channel configuration"],"tags":["kafka","spring","missing-bean","configuration"],"backgroundTag":"missing-required-config","analyzedSha":"d6d39ce1c69ff244f2d9dc6af756a9b95e865586","analyzedAt":"2026-09-11T06:41:19.413Z","contentChangedAt":"2026-09-11T06:41:19.413Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}