Confluence is inaccessible and displays a 'Could not find datasource' error after upgrade
Platform notice: Server and Data Center only. This article only applies to Atlassian products on the Server and Data Center platforms.
Support for Server* products ended on February 15th 2024. If you are running a Server product, you can visit the Atlassian Server end of support announcement to review your migration options.
*Except Fisheye and Crucible
Summary
When accessing Confluence after an upgrade, Confluence displays an HTTP 500 error on the landing page, along with the following message:
java.util.concurrent.CompletionException: com.atlassian.util.concurrent.LazyReference$InitializationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantedTransactionManager' defined in class path resource [databaseSubsystemContext.xml]: Invocation of init method failed; nested exception is com.atlassian.util.concurrent.LazyReference$InitializationException: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'tenantedLocalSessionFactoryBean5' defined in class path resource [productionDatabaseContext.xml]: Invocation of init method failed; nested exception is io.atlassian.util.concurrent.LazyReference$InitializationException: net.sf.hibernate.HibernateException: Could not find datasource
Environment
- Confluence Server or Data Center (any version) with a datasource connection to the database.
Diagnosis
Checking the <confluence-home>/logs/atlassian-confluence.log file, the following error can be found:
2020-09-01 15:05:11,945 ERROR [Catalina-utility-1] [sf.hibernate.connection.DatasourceConnectionProvider] configure Could not find datasource: java:comp/env/jdbc/confluence
javax.naming.NameNotFoundException: Name [jdbc/confluence] is not bound in this Context. Unable to find [jdbc].
This indicates that Confluence was unable to establish a database connection while the application was being started, as the datasource connection configuration could not be found.
Cause
When upgrading Confluence via the installer method, the installer will replace all files from the Confluence installation directory, and many customizations and settings from the previous installation files may need to be re-added, as stated in our Upgrading Confluence guide.
This includes the datasource connection definitions, which are stored inside the <confluence-install>/conf/server.xml
file. As such, since the datasource connection definitions are not present on the new server.xml
file following the Confluence upgrade, Confluence will not be able to find the necessary connection details in order to establish a database connection.
Solution
Edit the server.xml
file from the upgraded Confluence instance, and add back the same datasource connection details that were present before the upgrade. After that, Confluence can be started, and it will be able to locate the connection details once again.