testcontainers/testcontainers-java · error · IllegalStateException

Solr needs to have a configuration if you want to use a…

Error message

Solr needs to have a configuration if you want to use a schema

What it means

Same check as the deprecated modules/solr SolrContainer: a schema requires a configuration (solrconfig.xml) since Solr cores are created from a configset containing both. Thrown from configure() during container startup when the schema is set but the configuration is not.

Solutions

  1. Call withConfiguration(name, url-to-solrconfig.xml) before withSchema.
  2. Drop the schema override and rely on the _default configset if custom solrconfig isn't needed.
  3. Package schema.xml and solrconfig.xml together as a configset.

Example fix

// before
new org.testcontainers.solr.SolrContainer("solr:9")
    .withSchema(schemaUrl);
// after
new org.testcontainers.solr.SolrContainer("solr:9")
    .withConfiguration("custom", solrConfigUrl)
    .withSchema(schemaUrl);
Defensive patterns

Strategy: validation

Validate before calling

assert schemaUrl == null || configUrl != null : "a schema requires a solrconfig.xml configuration";

Prevention

When it happens

Trigger: org.testcontainers.solr.SolrContainer started after calling withSchema(...) without withConfiguration(...).

Common situations: Migrating from the old module and copying only the schema-related builder calls; assuming a default solrconfig is auto-supplied when only the schema is customized.

Understand the failure class

Background: Conflicting config options: "cannot be used together" — configuration validation errors across open-source libraries — this error's family across 162 libraries.

Related errors


AI-assisted analysis of testcontainers/testcontainers-java@8e549514e3 (2026-09-12). Data as JSON: /api/errors/17a70b84e6ae7fe1. Report an issue: GitHub.

Appendix: source

Thrown at modules/solr/src/main/java/org/testcontainers/solr/SolrContainer.java:95

    public SolrContainer withSchema(URL schema) {
        configuration.setSolrSchema(schema);
        return self();
    }

    public int getSolrPort() {
        return getMappedPort(SOLR_PORT);
    }

    public int getZookeeperPort() {
        return getMappedPort(ZOOKEEPER_PORT);
    }

    @Override
    @SneakyThrows
    protected void configure() {
        if (configuration.getSolrSchema() != null && configuration.getSolrConfiguration() == null) {
            throw new IllegalStateException("Solr needs to have a configuration if you want to use a schema");
        }
        // Generate Command Builder
        String command = "solr start -f";
        // Add Default Ports
        addExposedPort(SOLR_PORT);

        // Configure Zookeeper
        if (configuration.isZookeeper()) {
            addExposedPort(ZOOKEEPER_PORT);
            if (this.imageVersion.isGreaterThanOrEqualTo("9.7.0")) {
                command = "-DzkRun --host localhost";
            } else {
                command = "-DzkRun -h localhost";
            }
        }

        // Apply generated Command
        setCommand(command);

View on GitHub (pinned to 8e549514e3)