{"record":{"id":"6f980b10efd0c1bd","repo":"YunaiV/ruoyi-vue-pro","slug":"couldn-t-lookup-datasource-from","errorCode":null,"errorMessage":"couldn't lookup datasource from {}: {}","messagePattern":"couldn't lookup datasource from (.+?): (.+?)","errorType":"exception","errorClass":"FlowableException","httpStatus":null,"severity":"critical","filePath":"sql/dm/flowable-patch/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java","lineNumber":446,"sourceCode":"    /**\n     * Define a max length for storing String variable types in the database. Mainly used for the Oracle NVARCHAR2 limit of 2000 characters\n     */\n    protected int maxLengthStringVariableType = -1;\n\n    protected void initEngineConfigurations() {\n        addEngineConfiguration(getEngineCfgKey(), getEngineScopeType(), this);\n    }\n\n    // DataSource\n    // ///////////////////////////////////////////////////////////////\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 FlowableException(\"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 FlowableException(\"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                if (logger.isInfoEnabled()) {\n                    logger.info(\"Configuring Datasource with following properties (omitted password for security)\");\n                    logger.info(\"datasource driver : {}\", jdbcDriver);\n                    logger.info(\"datasource url : {}\", jdbcUrl);\n                    logger.info(\"datasource user name : {}\", jdbcUsername);\n                }\n\n                PooledDataSource pooledDataSource = new PooledDataSource(this.getClass().getClassLoader(), jdbcDriver, jdbcUrl, jdbcUsername, jdbcPassword);\n","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/YunaiV/ruoyi-vue-pro/blob/0418084e222612af2fc1141f566af454f9236ab1/sql/dm/flowable-patch/src/main/java/org/flowable/common/engine/impl/AbstractEngineConfiguration.java#L428-L464","documentation":"Flowable's AbstractEngineConfiguration.initDataSource() tries a JNDI lookup (new InitialContext().lookup(dataSourceJndiName)) when dataSource is null but dataSourceJndiName is set. If the JNDI name is unbound or the naming provider is unreachable, the lookup throws and Flowable wraps it as a FlowableException with the JNDI name and root cause message.","triggerScenarios":"dataSourceJndiName is configured but the resource is not registered in the app server's JNDI tree; deploying a WAR to Tomcat/JBoss without the declared <Resource>; JNDI name typo (e.g. 'jdbc/myDs' vs 'java:comp/env/jdbc/myDs'); running outside a container that lacks a JNDI provider.","commonSituations":"Moving from embedded datasource (H2) to JNDI in production but forgetting to add the Resource in context.xml/server.xml; running Flowable in a plain main() without a naming context.","solutions":["Confirm the JNDI name exactly matches what is registered in the container (use java:comp/env/ prefix where required).","Register the datasource resource in the app server (Tomcat context.xml, JBoss -ds.xml, etc.).","If running outside a container, set jdbcUrl/jdbcDriver/jdbcUsername instead of dataSourceJndiName, or inject a DataSource bean directly.","Inspect the caused-by message (NamingException) for 'Name not found' vs 'communication refused' to distinguish missing binding from unreachable provider."],"exampleFix":"// before\ncfg.setDataSourceJndiName(\"jdbc/myDs\");\n// after\ncfg.setDataSourceJndiName(\"java:comp/env/jdbc/myDs\");\n// plus context.xml:\n// <Resource name=\"jdbc/myDs\" auth=\"Container\" type=\"javax.sql.DataSource\" .../>","handlingStrategy":"validation","validationCode":"if (cfg.getDataSourceJndiName() != null) {\n    try {\n        new InitialContext().lookup(cfg.getDataSourceJndiName());\n    } catch (NamingException e) {\n        throw new IllegalStateException(\"JNDI name not bound: \" + cfg.getDataSourceJndiName(), e);\n    }\n}","typeGuard":"null","tryCatchPattern":"try {\n    engine = cfg.buildProcessEngine();\n} catch (FlowableException e) {\n    if (e.getMessage().contains(\"couldn't lookup datasource\")) { /* fall back to JDBC props */ }\n    throw e;\n}","preventionTips":["Register the JNDI Resource in the container before deploy","Use the exact JNDI name (java:comp/env/...) returned by the server JNDI tree","For non-container runs, prefer JDBC properties or an injected DataSource bean"],"tags":["flowable","jndi","datasource","configuration"],"backgroundTag":null,"analyzedSha":"0418084e222612af2fc1141f566af454f9236ab1","analyzedAt":"2026-08-14T00:56:18.412Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}