{"record":{"id":"4b2fc76186ced1e4","repo":"testcontainers/testcontainers-java","slug":"solr-needs-to-have-a-configuration-if-you-want-to-use-a","errorCode":null,"errorMessage":"Solr needs to have a configuration if you want to use a schema","messagePattern":"Solr needs to have a configuration if you want to use a schema","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"modules/solr/src/main/java/org/testcontainers/containers/SolrContainer.java","lineNumber":107,"sourceCode":"\n    public SolrContainer withSchema(URL schema) {\n        configuration.setSolrSchema(schema);\n        return self();\n    }\n\n    public int getSolrPort() {\n        return getMappedPort(SOLR_PORT);\n    }\n\n    public int getZookeeperPort() {\n        return getMappedPort(ZOOKEEPER_PORT);\n    }\n\n    @Override\n    @SneakyThrows\n    protected void configure() {\n        if (configuration.getSolrSchema() != null && configuration.getSolrConfiguration() == null) {\n            throw new IllegalStateException(\"Solr needs to have a configuration if you want to use a schema\");\n        }\n        // Generate Command Builder\n        String command = \"solr start -f\";\n        // Add Default Ports\n        this.addExposedPort(SOLR_PORT);\n\n        // Configure Zookeeper\n        if (configuration.isZookeeper()) {\n            this.addExposedPort(ZOOKEEPER_PORT);\n            if (this.imageVersion.isGreaterThanOrEqualTo(\"9.7.0\")) {\n                command = \"-DzkRun --host localhost\";\n            } else {\n                command = \"-DzkRun -h localhost\";\n            }\n        }\n\n        // Apply generated Command\n        this.setCommand(command);","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/solr/src/main/java/org/testcontainers/containers/SolrContainer.java#L89-L125","documentation":"Testcontainers' SolrContainer requires a Solr configuration (solrconfig.xml) whenever a custom schema is supplied, because Solr cores are created from a configset that bundles both files. Thrown from configure() at container start when getSolrSchema() is set but getSolrConfiguration() is null.","triggerScenarios":"Calling withSolrSchema(...) (or withSchema) without a preceding withConfiguration(...) before starting the container.","commonSituations":"Developers customize the schema for custom fields but assume a default solrconfig.xml is generated; copying config code from examples that only set the configuration and forgetting it works both ways.","solutions":["Add a withConfiguration(name, url-to-solrconfig.xml) call alongside withSchema.","If you don't need a custom solrconfig, use the default configset (_default) and drop the schema override.","Bundle both files in a configset directory and reference them together."],"exampleFix":"// before\nnew SolrContainer(DockerImageName.parse(\"solr:8\"))\n    .withCollection(\"items\")\n    .withSchema(new File(\"schema.xml\").toURI().toURL());\n// after\nnew SolrContainer(DockerImageName.parse(\"solr:8\"))\n    .withCollection(\"items\")\n    .withConfiguration(\"custom\", new File(\"solrconfig.xml\").toURI().toURL())\n    .withSchema(new File(\"schema.xml\").toURI().toURL());","handlingStrategy":"validation","validationCode":"assert container.getSolrSchema() == null || container.getSolrConfiguration() != null : \"withSchema requires withConfiguration\";","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pair withSchema with withConfiguration in a shared container factory method.","Wrap Solr container creation in a helper so configset files are always supplied together."],"tags":["solr","testcontainers","configuration"],"backgroundTag":"conflicting-config-options","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}