{"record":{"id":"8c25175589a9c54f","repo":"Activiti/Activiti","slug":"couldn-t-lookup-datasource-from","errorCode":null,"errorMessage":"couldn't lookup datasource from : ","messagePattern":"couldn't lookup datasource from : ","errorType":"exception","errorClass":"ActivitiException","httpStatus":null,"severity":"critical","filePath":"activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java","lineNumber":1056,"sourceCode":"        initService(dynamicBpmnService);\n    }\n\n    public void initService(Object service) {\n        if (service instanceof ServiceImpl) {\n            ((ServiceImpl) service).setCommandExecutor(commandExecutor);\n        }\n    }\n\n    // DataSource\n    // ///////////////////////////////////////////////////////////////\n\n    public 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(\n                        \"couldn't lookup datasource from \" + dataSourceJndiName + \": \" + e.getMessage(),\n                        e\n                    );\n                }\n            } else if (jdbcUrl != null) {\n                if ((jdbcDriver == null) || (jdbcUsername == null)) {\n                    throw new ActivitiException(\n                        \"DataSource or JDBC properties have to be specified in a process engine configuration\"\n                    );\n                }\n\n                log.debug(\"initializing datasource to db: {}\", jdbcUrl);\n\n                PooledDataSource pooledDataSource = new PooledDataSource(\n                    ReflectUtil.getClassLoader(),\n                    jdbcDriver,\n                    jdbcUrl,\n                    jdbcUsername,","sourceCodeStart":1038,"sourceCodeEnd":1074,"githubUrl":"https://github.com/Activiti/Activiti/blob/56435b1a97deeafdc09dd40074b056c89fba5a8a/activiti-core/activiti-engine/src/main/java/org/activiti/engine/impl/cfg/ProcessEngineConfigurationImpl.java#L1038-L1074","documentation":"When no DataSource object is configured, the engine tries to resolve one via JNDI using the configured dataSourceJndiName. If the InitialContext lookup fails (name not bound, no JNDI provider, wrong type), the NamingException's message is wrapped in this ActivitiException with the original as cause.","triggerScenarios":"processEngineConfiguration.initDataSource() with dataSource == null and dataSourceJndiName set, when InitialContext().lookup(jndiName) throws — e.g. 'jdbc/activitiDS' not bound, running outside the app server, or NameNotFoundException.","commonSituations":"Typo in the JNDI name vs the server's resource definition (persistence.xml/web.xml/datasource XML); running unit tests outside the container where no JNDI exists; datasource not deployed/started; missing jee namespace resource-ref mapping in Tomcat.","solutions":["Verify the JNDI name exactly matches the bound datasource (check server startup logs / admin console for the bound name) and fix setDataSourceJndiName(...).","Ensure you are running inside the environment providing the JNDI context (app server) or add a jndi.properties/InitialContext factory for tests.","Alternatively skip JNDI and configure a direct DataSource or jdbcUrl/jdbcDriver/jdbcUsername/jdbcPassword properties on the configuration."],"exampleFix":"// before\ncfg.setDataSourceJndiName(\"java:jdbc/ActivitiDS\"); // name not bound\n// after (Tomcat example)\ncfg.setDataSourceJndiName(\"java:comp/env/jdbc/activitiDS\");\n// or bypass JNDI\ncfg.setJdbcUrl(\"jdbc:h2:tcp://localhost/activiti\");\ncfg.setJdbcDriver(\"org.h2.Driver\");","handlingStrategy":"validation","validationCode":"// verify JNDI binding before configuring the engine\ntry {\n    Object ds = new InitialContext().lookup(\"java:comp/env/jdbc/activitiDS\");\n    assert ds instanceof javax.sql.DataSource;\n} catch (NamingException e) {\n    throw new IllegalStateException(\"Datasource not bound at expected JNDI name\", e);\n}","typeGuard":null,"tryCatchPattern":"try {\n    engine = cfg.buildProcessEngine();\n} catch (ActivitiException e) {\n    if (e.getMessage().startsWith(\"couldn't lookup datasource\")) {\n        // fall back to direct JDBC config\n        cfg.setJdbcUrl(...); cfg.setJdbcDriver(...); cfg.setJdbcUsername(...); cfg.setJdbcPassword(...);\n        engine = cfg.buildProcessEngine();\n    } else throw e;\n}","preventionTips":["Copy the exact JNDI name from the server's bound-resources listing","Prefer injecting a DataSource bean over JNDI in tests","Always inspect getCause() — the NamingException names the missing binding"],"tags":["activiti","jndi","datasource","configuration"],"backgroundTag":"missing-config-value","analyzedSha":"56435b1a97deeafdc09dd40074b056c89fba5a8a","analyzedAt":"2026-09-09T21:00:06.703Z","contentChangedAt":"2026-09-09T21:00:06.703Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}