{"record":{"id":"8e0f1e1f8f603718","repo":"spring-projects/spring-boot","slug":"failed-to-load-layers-configuration-with-name-s","errorCode":null,"errorMessage":"Failed to load layers configuration with name '%s': '%s' not found","messagePattern":"Failed to load layers configuration with name '(.+?)': '(.+?)' not found","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractPackagerMojo.java","lineNumber":215,"sourceCode":"\t}\n\n\tprivate org.springframework.boot.loader.tools.Layers loadLayersConfiguration() {\n\t\tFile configuration = this.layers.getConfiguration();\n\t\tif (configuration != null) {\n\t\t\treturn getCustomLayers(configuration.getAbsolutePath(), () -> new FileInputStream(configuration));\n\t\t}\n\t\tString configurationName = this.layers.getConfigurationName();\n\t\tif (configurationName != null) {\n\t\t\tString location = \"META-INF/spring/layers/%s.xml\".formatted(configurationName);\n\t\t\treturn getCustomLayers(location, () -> loadLayersConfigurationFromClasspath(configurationName, location));\n\t\t}\n\t\treturn IMPLICIT_LAYERS;\n\t}\n\n\tprivate InputStream loadLayersConfigurationFromClasspath(String name, String location) {\n\t\tInputStream in = this.pluginDescriptor.getClassRealm().getResourceAsStream(location);\n\t\tif (in == null) {\n\t\t\tthrow new IllegalStateException(\n\t\t\t\t\t\"Failed to load layers configuration with name '%s': '%s' not found\".formatted(name, location));\n\t\t}\n\t\treturn in;\n\t}\n\n\tprivate CustomLayers getCustomLayers(String source, InputStreamSource inputStreamSource) {\n\t\ttry {\n\t\t\tDocument document = getDocumentIfAvailable(inputStreamSource);\n\t\t\treturn new CustomLayersProvider().getLayers(document);\n\t\t}\n\t\tcatch (Exception ex) {\n\t\t\tthrow new IllegalStateException(\"Failed to process custom layers configuration \" + source, ex);\n\t\t}\n\t}\n\n\tprivate Document getDocumentIfAvailable(InputStreamSource source) throws Exception {\n\t\ttry (InputStream in = source.getInputStream()) {\n\t\t\tInputSource inputSource = new InputSource(in);","sourceCodeStart":197,"sourceCodeEnd":233,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/270dfe353fb830fd69b823a8a859287ff103854b/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/AbstractPackagerMojo.java#L197-L233","documentation":"Thrown by AbstractPackagerMojo.loadLayersConfigurationFromClasspath when the plugin's class realm cannot resolve the resource META-INF/spring/layers/<configurationName>.xml. The layers feature lets you split a fat jar into layers for better Docker caching; a named configuration must exist as a classpath resource at that exact location. A null InputStream means the resource is absent from every JAR/plugin dependency the realm can see.","triggerScenarios":"Setting <layers><configurationName>foo</configurationName></layers> in the plugin config when no META-INF/spring/layers/foo.xml is present on the plugin descriptor's class realm (getResourceAsStream returns null). Triggered during repackage/build-image when layers are enabled and a configurationName is supplied.","commonSituations":"Typo in configurationName; resource shipped in the application JAR instead of a plugin dependency the realm sees; resource placed under src/main/resources of the app rather than the plugin; upgrading Spring Boot and the legacy layers.xml path moved; custom layer config only declared but never added to the build classpath.","solutions":["Verify the exact resource path: the file must live at META-INF/spring/layers/<configurationName>.xml inside a JAR that the maven plugin can load (a plugin dependency, not just the application classpath).","Correct the <configurationName> value to match the filename (without .xml) of an existing layers.xml.","If using a custom layers file, bundle it in a dependency JAR listed under <plugin><dependencies> for spring-boot-maven-plugin, or drop the configurationName to fall back to IMPLICIT_LAYERS.","Rebuild the artifact that is supposed to carry the resource and confirm with `jar tf <artifact>.jar | grep 'META-INF/spring/layers'` that the file is actually packaged."],"exampleFix":"// before: <layers><configurationName>cunstom</configurationName></layers>\n// after:  <layers><configurationName>custom</configurationName></layers>  // matches META-INF/spring/layers/custom.xml","handlingStrategy":"validation","validationCode":"// Before configuring <layers><configurationName>NAME</configurationName></layers>:\nString name = /* configured value */;\nString loc = \"META-INF/spring/layers/\" + name + \".xml\";\ntry (var in = Thread.currentThread().getContextClassLoader().getResourceAsStream(loc)) {\n    if (in == null) {\n        throw new IllegalStateException(\"Missing layers resource: \" + loc\n            + \" — verify the file ships in a plugin dependency the realm can see.\");\n    }\n}","typeGuard":null,"tryCatchPattern":"// In a build-extension wrapper around the plugin goal:\ntry {\n    // invoke repackage/build-image\n} catch (IllegalStateException ex) {\n    if (ex.getMessage().startsWith(\"Failed to load layers configuration\")) {\n        // surface a hint pointing at META-INF/spring/layers/<name>.xml\n    }\n    throw ex;\n}","preventionTips":["Keep the layers.xml filename and <configurationName> in sync via a single property.","Run `jar tf <plugin-dep>.jar | grep META-INF/spring/layers` in CI to assert the resource exists.","Omit <configurationName> when the default IMPLICIT_LAYERS is acceptable."],"tags":["spring-boot","maven-plugin","layers","classpath","configuration"],"backgroundTag":null,"analyzedSha":"270dfe353fb830fd69b823a8a859287ff103854b","analyzedAt":"2026-08-11T19:42:06.541Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}