quarkusio/quarkus · error · IllegalArgumentException
No datasource named '<dataSourceName>' exists
Error message
No datasource named '<dataSourceName>' exists
What it means
DataSources.createDataSource() initializes datasources at runtime from the build-time registered entries in agroalDataSourceSupport. Requesting a datasource name that was not defined/registered at build time throws this IllegalArgumentException immediately.
Source
Thrown at extensions/agroal/runtime/src/main/java/io/quarkus/agroal/runtime/DataSources.java:146
*/
@Deprecated
public Set<String> getActiveDataSourceNames() {
return AgroalDataSourceUtil.activeDataSourceNames();
}
/**
* @deprecated Use {@link AgroalDataSourceUtil#dataSourceInstance(String)} instead.
*/
@Deprecated
public AgroalDataSource getDataSource(String dataSourceName) {
return ClientProxy.unwrap(AgroalDataSourceUtil.dataSourceInstance(dataSourceName).get());
}
@SuppressWarnings("resource")
public AgroalDataSource createDataSource(String dataSourceName, boolean otelEnabled,
Map<String, String> buildTimeJdbcProperties) {
if (!agroalDataSourceSupport.entries.containsKey(dataSourceName)) {
throw new IllegalArgumentException("No datasource named '" + dataSourceName + "' exists");
}
DataSourceJdbcBuildTimeConfig dataSourceJdbcBuildTimeConfig = dataSourcesJdbcBuildTimeConfig
.dataSources().get(dataSourceName).jdbc();
DataSourceRuntimeConfig dataSourceRuntimeConfig = dataSourcesRuntimeConfig.dataSources().get(dataSourceName);
DataSourceJdbcRuntimeConfig dataSourceJdbcRuntimeConfig = dataSourcesJdbcRuntimeConfig
.dataSources().get(dataSourceName).jdbc();
if (!dataSourceJdbcRuntimeConfig.url().isPresent()) {
throw new IllegalArgumentException(
"Datasource " + dataSourceName + " does not have a JDBC URL and should not be created");
}
// we first make sure that all available JDBC drivers are loaded in the current TCCL
loadDriversInTCCL();
AgroalDataSourceSupport.Entry matchingSupportEntry = agroalDataSourceSupport.entries.get(dataSourceName);
String resolvedDriverClass = matchingSupportEntry.resolvedDriverClass;View on GitHub (pinned to e1c734241f)
Solutions
- Define the datasource in configuration (quarkus.datasource.<name>.db-kind=... plus URL/credentials) so it is registered at build time.
- Fix the datasource name used at the lookup/injection site to match a configured datasource.
- Verify the config profile (e.g. %prod) actually defines the datasource for the active runtime profile.
Example fix
// before
@Inject @DataSourceName("inventory") AgroalDataSource ds; // never configured
// after
quarkus.datasource.inventory.db-kind=postgresql
quarkus.datasource.inventory.jdbc.url=jdbc:postgresql://localhost:5432/inventory
// and/or use an existing name:
@Inject @DataSourceName("inventory") AgroalDataSource ds; Defensive patterns
Strategy: validation
Validate before calling
String name = "inventory";
if (ConfigProvider.getConfig().getOptionalValue("quarkus.datasource." + name + ".db-kind", String.class).isEmpty()) {
throw new IllegalStateException("Datasource '" + name + "' is not configured at build time");
} Try / catch
try { ds = dataSources.createDataSource(name, false, Map.of()); } catch (IllegalArgumentException e) { if (e.getMessage().startsWith("No datasource named")) { log.error("Datasource not defined in config: " + name); } throw e; } Prevention
- Define every datasource name used in code in application.properties with at least db-kind and jdbc.url.
- Check active profile (%prod, %dev) actually defines the named datasource.
- Inject datasources via @Inject @DataSourceId/... instead of hardcoding names where possible.
When it happens
Trigger: createDataSource(dataSourceName, otelEnabled, buildTimeJdbcProperties) is called (from apply) and !agroalDataSourceSupport.entries.containsKey(dataSourceName) — i.e. the named datasource was never configured at build time.
Common situations: @AgroalDataSource or code requesting a datasource whose quarkus.datasource.<name>.* properties were never set; renaming a datasource in config while startup code still uses the old name; typo in the datasource name at the injection/lookup site.
Related errors
- Unable to load the datasource driver <driverName> for the <f
- quarkus.datasource.url and quarkus.datasource.driver have be
- Proxy configuration with name ${key} was requested but quark
- Quartz datasource resolution can be either deferred to runti
- JDBC Store configured but the '%s' datasource is not configu
AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05).
Data as JSON: /api/errors/767b5324697e3d1b.
Report an issue: GitHub.