{"record":{"id":"6e861df13a49c18e","repo":"apereo/cas","slug":"lookup-of-datasource-failed-due-to-back","errorCode":null,"errorMessage":"Lookup of datasource [{}] failed due to [{}]. Back to JPA properties.","messagePattern":"Lookup of datasource \\[(.+?)\\] failed due to \\[(.+?)\\]\\. Back to JPA properties\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"support/cas-server-support-jpa-util/src/main/java/org/apereo/cas/configuration/support/JpaBeans.java","lineNumber":118,"sourceCode":"     * <p>\n     * If user wants to do lookup as resource, they may include {@code java:/comp/env}\n     * in {@code dataSourceName} and put resource reference in web.xml\n     * otherwise {@code dataSourceName} is used as JNDI name.\n     *\n     * @param jpaProperties the jpa properties\n     * @return the data source\n     */\n    public CloseableDataSource newDataSource(final AbstractJpaProperties jpaProperties) {\n        val dataSourceName = jpaProperties.getDataSourceName();\n\n        if (StringUtils.isNotBlank(dataSourceName)) {\n            try {\n                val dsLookup = new JndiDataSourceLookup();\n                dsLookup.setResourceRef(false);\n                val containerDataSource = dsLookup.getDataSource(dataSourceName);\n                return new DefaultCloseableDataSource(containerDataSource);\n            } catch (final DataSourceLookupFailureException e) {\n                LOGGER.warn(\"Lookup of datasource [{}] failed due to [{}]. Back to JPA properties.\", dataSourceName, e.getMessage());\n            }\n        }\n\n        val bean = new HikariDataSource();\n        FunctionUtils.doIfNotBlank(jpaProperties.getDriverClass(), _ -> bean.setDriverClassName(jpaProperties.getDriverClass()));\n\n        val url = SpringExpressionLanguageValueResolver.getInstance().resolve(jpaProperties.getUrl());\n        bean.setJdbcUrl(url);\n        bean.setUsername(jpaProperties.getUser());\n        bean.setPassword(jpaProperties.getPassword());\n\n        val poolSettings = jpaProperties.getPool();\n        FunctionUtils.doUnchecked(_ -> bean.setLoginTimeout((int) Beans.newDuration(poolSettings.getMaxWait()).toSeconds()));\n        bean.setMaximumPoolSize(poolSettings.getMaxSize());\n        bean.setMinimumIdle(poolSettings.getMinSize());\n        bean.setIdleTimeout(Beans.newDuration(jpaProperties.getIdleTimeout()).toMillis());\n        bean.setLeakDetectionThreshold(Beans.newDuration(jpaProperties.getLeakThreshold()).toMillis());\n        bean.setInitializationFailTimeout(jpaProperties.getFailFastTimeout());","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/support/cas-server-support-jpa-util/src/main/java/org/apereo/cas/configuration/support/JpaBeans.java#L100-L136","documentation":"JpaBeans.newDataSource first tries to resolve the configured datasource name via JNDI (JndiDataSourceLookup). If the lookup throws DataSourceLookupFailureException - the name is not bound in the container's JNDI tree - it logs this WARN and falls back to building a HikariDataSource from the JPA properties (driver class, URL, user, password). It is a recoverable fallback, not a fatal error; the returned pool just uses local JDBC settings instead of the container-managed datasource.","triggerScenarios":"Configuring a JPA module (cas.authn.jpa, tickets-jpa, services-jpa, etc.) with a dataSourceName while running outside a servlet container that exposes that JNDI resource; JNDI name typo or missing <Resource>/resource-ref declaration; deploying the CAS WAR standalone (embedded container) where no JNDI datasource is provisioned.","commonSituations":"Running CAS via embedded Tomcat/Jetty in dev where no JNDI datasource is bound; moving an app from app-server deployment to standalone and forgetting to remove dataSourceName; JNDI binding present only after datasource resource is declared in server config.","solutions":["Declare the JNDI datasource in the servlet container (context.xml Resource, server datasource config) so the lookup succeeds","Remove/clear the dataSourceName property so CAS skips the JNDI attempt and builds the Hikari pool directly from JPA properties","Ensure jpaProperties (url, driverClass, user, password) are fully populated since they are used for the fallback","Verify the exact JNDI name string matches the container binding, including java:comp/env prefixing behavior"],"exampleFix":"// before\ncas.authn.jpa.dataSourceName=jdbc/casDb\n// after\ncas.authn.jpa.url=jdbc:postgresql://db:5432/cas\ncas.authn.jpa.driverClass=org.postgresql.Driver\ncas.authn.jpa.user=cam\ncas.authn.jpa.password=secret","handlingStrategy":"fallback","validationCode":"try { new javax.naming.InitialContext().lookup(\"java:comp/env/jdbc/casDb\"); } catch (NamingException e) { System.out.println(\"JNDI ds missing - ensure JPA url/driver/user/password are set\"); }","typeGuard":null,"tryCatchPattern":"try { dataSource = new InitialContext().lookup(\"java:comp/env/jdbc/casDb\"); } catch (NamingException e) { LOGGER.warn(\"JNDI lookup failed; using Hikari from JPA properties\", e); dataSource = buildHikari(jpaProperties); }","preventionTips":["Only set dataSourceName when deploying to a container that actually binds the JNDI resource","Keep JPA url/driverClass/user/password configured as fallback even when using JNDI","Match JNDI names exactly between CAS config and container resource declarations","Watch logs at startup for the fallback warning to know which pool is active"],"tags":["jndi","datasource","hikari","fallback","jpa"],"backgroundTag":"connection-refused","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}