{"id":"ac51669aa4264952","repo":"spring-projects/spring-boot","slug":"invalid-layers-xml-configuration","errorCode":null,"errorMessage":"Invalid layers.xml configuration","messagePattern":"Invalid layers\\.xml configuration","errorType":"exception","errorClass":"IllegalStateException","httpStatus":null,"severity":"error","filePath":"build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java","lineNumber":72,"sourceCode":"class CustomLayersProvider {\n\n\tCustomLayers getLayers(Document document) {\n\t\tvalidate(document);\n\t\tElement root = document.getDocumentElement();\n\t\tList<ContentSelector<String>> applicationSelectors = getApplicationSelectors(root);\n\t\tList<ContentSelector<Library>> librarySelectors = getLibrarySelectors(root);\n\t\tList<Layer> layers = getLayers(root);\n\t\treturn new CustomLayers(layers, applicationSelectors, librarySelectors);\n\t}\n\n\tprivate void validate(Document document) {\n\t\tSchema schema = loadSchema();\n\t\ttry {\n\t\t\tValidator validator = schema.newValidator();\n\t\t\tvalidator.validate(new DOMSource(document));\n\t\t}\n\t\tcatch (SAXException | IOException ex) {\n\t\t\tthrow new IllegalStateException(\"Invalid layers.xml configuration\", ex);\n\t\t}\n\t}\n\n\tprivate Schema loadSchema() {\n\t\ttry {\n\t\t\tSchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\n\t\t\treturn factory.newSchema(getClass().getResource(\"layers.xsd\"));\n\t\t}\n\t\tcatch (SAXException ex) {\n\t\t\tthrow new IllegalStateException(\"Unable to load layers XSD\");\n\t\t}\n\t}\n\n\tprivate List<ContentSelector<String>> getApplicationSelectors(Element root) {\n\t\treturn getSelectors(root, \"application\", (element) -> getSelector(element, ApplicationContentFilter::new));\n\t}\n\n\tprivate List<ContentSelector<Library>> getLibrarySelectors(Element root) {","sourceCodeStart":54,"sourceCodeEnd":90,"githubUrl":"https://github.com/spring-projects/spring-boot/blob/5b2dbdbb8be64415eb6552f81ff7c449c8d251e6/build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/CustomLayersProvider.java#L54-L90","documentation":"Thrown by CustomLayersProvider.validate as an IllegalStateException when the parsed layers.xml document fails XSD validation (SAXException) or cannot be read by the Validator (IOException). The document was already parsed as XML (so it is well-formed); this error means it violates the schema defined by layers.xsd — wrong element names, unexpected child structure, invalid attribute values, etc.","triggerScenarios":"A layers.xml that is well-formed XML but uses elements or attributes not allowed by the Spring Boot layers XSD for the plugin version in use; an <include>/<exclude> with content that the schema restricts; a <layerOrder> with an empty <layer/> when the schema requires text content; migrating a layers.xml across Spring Boot major versions where the XSD changed.","commonSituations":"Copying a layers.xml sample from an older Spring Boot doc into a newer plugin; hand-authoring layers.xml without consulting the XSD; adding custom elements that the schema does not permit.","solutions":["Open layers.xsd bundled with your Spring Boot version (org/springframework/boot/maven/layers.xsd) and align your layers.xml to it.","Read the wrapped SAXException — it names the failing element/attribute and the XSD rule.","Replace the custom layers.xml with a minimal valid one and re-add complexity incrementally.","Consult the Spring Boot reference for layers configuration matching your version."],"exampleFix":"// before — element not allowed by XSD\n<application>\n  <selection layer=\"deps\"><include>**/*.class</include></selection>\n</application>\n// after — schema-correct element names\n<application>\n  <into layer=\"deps\"><include>**/*.class</include></into>\n</application>","handlingStrategy":"validation","validationCode":"// Validate layers.xml against the bundled XSD at build time\nimport javax.xml.validation.SchemaFactory, Validator, Schema;\nimport javax.xml.XMLConstants;\nimport javax.xml.transform.stream.StreamSource;\nimport java.io.File;\n\nvoid validate(File layersXml, File layersXsd) throws Exception {\n    SchemaFactory sf = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);\n    Schema s = sf.newSchema(layersXsd);\n    s.newValidator().validate(new StreamSource(layersXml));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a copy of the layers.xsd for your Spring Boot version alongside the config.","Add an integration test that validates layers.xml against the XSD on every build.","Pin the plugin version to avoid silent XSD changes between upgrades."],"tags":["maven","spring-boot","layers","xml","xsd","validation"],"analyzedSha":"5b2dbdbb8be64415eb6552f81ff7c449c8d251e6","analyzedAt":"2026-08-04T18:53:14.967Z","schemaVersion":2}