{"record":{"id":"9174e6d97f24f57f","repo":"flowable/flowable-engine","slug":"couldn-t-lookup-datasource-from-datasourcejndina","errorCode":null,"errorMessage":"couldn't lookup datasource from ${dataSourceJndiName}: ${e.getMessage()}","messagePattern":"couldn't lookup datasource from (.+?): (.+?)","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"critical","filePath":"modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java","lineNumber":725,"sourceCode":"        initService(managementService);\n        initService(dynamicBpmnService);\n    }\n\n    protected void initService(Object service) {\n        if (service instanceof ServiceImpl) {\n            ((ServiceImpl) service).setCommandExecutor(commandExecutor);\n        }\n    }\n\n    // DataSource ///////////////////////////////////////////////////////////////\n\n    protected void initDataSource() {\n        if (dataSource == null) {\n            if (dataSourceJndiName != null) {\n                try {\n                    dataSource = (DataSource) new InitialContext().lookup(dataSourceJndiName);\n                } catch (Exception e) {\n                    throw new ActivitiException(\"couldn't lookup datasource from \" + dataSourceJndiName + \": \" + e.getMessage(), e);\n                }\n\n            } else if (jdbcUrl != null) {\n                if ((jdbcDriver == null) || (jdbcUsername == null)) {\n                    throw new ActivitiException(\"DataSource or JDBC properties have to be specified in a process engine configuration\");\n                }\n\n                LOGGER.debug(\"initializing datasource to db: {}\", jdbcUrl);\n\n                PooledDataSource pooledDataSource = new PooledDataSource(ReflectUtil.getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);\n\n                if (jdbcMaxActiveConnections > 0) {\n                    pooledDataSource.setPoolMaximumActiveConnections(jdbcMaxActiveConnections);\n                }\n                if (jdbcMaxIdleConnections > 0) {\n                    pooledDataSource.setPoolMaximumIdleConnections(jdbcMaxIdleConnections);\n                }\n                if (jdbcMaxCheckoutTime > 0) {","sourceCodeStart":707,"sourceCodeEnd":743,"githubUrl":"https://github.com/flowable/flowable-engine/blob/d6d39ce1c69ff244f2d9dc6af756a9b95e865586/modules/flowable5-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java#L707-L743","documentation":"When no explicit DataSource is configured, the engine can look one up via JNDI using dataSourceJndiName. If InitialContext().lookup fails (name not bound, wrong name, no container JNDI), the engine wraps the failure in this ActivitiException preserving the original message.","triggerScenarios":"Setting dataSourceJndiName to a JNDI path that is not bound in the naming context (typo, missing resource definition in app server), or running outside an app server where InitialContext has no JNDI provider configured.","commonSituations":"Deploying the same war to Tomcat (no default JNDI DataSource) after it worked on WildFly; datasource removed/renamed in server config (e.g. jetty/env or context.xml); the JNDI name missing the required java:comp/env or java:/ prefix.","solutions":["Verify the JNDI name matches the bound resource exactly, including prefix (e.g. java:comp/env/jdbc/ActivitiDS or java:/jdbc/ActivitiDS)","Define the DataSource resource in the server (context.xml / *-ds.xml / server resources) so the name exists","Alternatively set dataSource directly (or jdbcUrl/jdbcDriver/jdbcUsername) instead of relying on JNDI","Check the nested e.getMessage() — NamingException details indicate whether the name or the provider is wrong"],"exampleFix":"// before\ncfg.setDataSourceJndiName(\"jdbc/ActivitiDS\");\n// after\ncfg.setDataSourceJndiName(\"java:comp/env/jdbc/ActivitiDS\");","handlingStrategy":"try-catch","validationCode":"try {\n  new InitialContext().lookup(dataSourceJndiName);\n} catch (NamingException e) {\n  throw new IllegalStateException(\"JNDI name not bound: \" + dataSourceJndiName, e);\n} // run this check before buildProcessEngine()","typeGuard":null,"tryCatchPattern":"try {\n  processEngine = cfg.buildProcessEngine();\n} catch (ActivitiException e) {\n  if (e.getMessage().startsWith(\"couldn't lookup datasource\")) {\n    log.error(\"JNDI lookup failed for {}: {}\", cfg.getDataSourceJndiName(), e.getMessage());\n    throw new DataSourceConfigurationException(e);\n  } else throw e;\n}","preventionTips":["Verify the exact bound JNDI name including java:comp/env or java:/ prefix","Declare the DataSource in the server config before deploying the app","Prefer injecting a DataSource bean directly over JNDI strings in tests/local runs","Check the cause message to distinguish missing name vs missing JNDI provider"],"tags":["activiti","jndi","datasource","configuration"],"backgroundTag":"resource-not-found","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"}