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

  1. Define the datasource in configuration (quarkus.datasource.<name>.db-kind=... plus URL/credentials) so it is registered at build time.
  2. Fix the datasource name used at the lookup/injection site to match a configured datasource.
  3. 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

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


AI-assisted analysis of quarkusio/quarkus@e1c734241f (2026-09-05). Data as JSON: /api/errors/767b5324697e3d1b. Report an issue: GitHub.