{"record":{"id":"e59102c0b6388f5d","repo":"baomidou/mybatis-plus","slug":"failed-to-parse-config-resource","errorCode":null,"errorMessage":"Failed to parse config resource: ","messagePattern":"Failed to parse config resource: ","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"critical","filePath":"mybatis-plus-spring/src/main/java/com/baomidou/mybatisplus/spring/MybatisSqlSessionFactoryBean.java","lineNumber":661,"sourceCode":"        Optional.ofNullable(this.defaultScriptingLanguageDriver)\n            .ifPresent(targetConfiguration::setDefaultScriptingLanguage);\n\n        if (this.databaseIdProvider != null) {// fix #64 set databaseId before parse mapper xmls\n            try {\n                targetConfiguration.setDatabaseId(this.databaseIdProvider.getDatabaseId(this.dataSource));\n            } catch (SQLException e) {\n                throw new IOException(\"Failed getting a databaseId\", e);\n            }\n        }\n\n        Optional.ofNullable(this.cache).ifPresent(targetConfiguration::addCache);\n\n        if (xmlConfigBuilder != null) {\n            try {\n                xmlConfigBuilder.parse();\n                LOGGER.debug(() -> \"Parsed configuration file: '\" + this.configLocation + \"'\");\n            } catch (Exception ex) {\n                throw new IOException(\"Failed to parse config resource: \" + this.configLocation, ex);\n            } finally {\n                ErrorContext.instance().reset();\n            }\n        }\n\n        targetConfiguration.setEnvironment(new Environment(this.environment,\n            this.transactionFactory == null ? new SpringManagedTransactionFactory() : this.transactionFactory,\n            this.dataSource));\n\n        if (this.mapperLocations != null) {\n            if (this.mapperLocations.length == 0) {\n                LOGGER.warn(() -> \"Property 'mapperLocations' was specified but matching resources are not found.\");\n            } else {\n                for (Resource mapperLocation : this.mapperLocations) {\n                    if (mapperLocation == null) {\n                        continue;\n                    }\n                    try {","sourceCodeStart":643,"sourceCodeEnd":679,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-spring/src/main/java/com/baomidou/mybatisplus/spring/MybatisSqlSessionFactoryBean.java#L643-L679","documentation":"Thrown by MybatisSqlSessionFactoryBean.buildSqlSessionFactory when the MyBatis configuration XML (configLocation resource) fails to parse: any exception from xmlConfigBuilder.parse() is wrapped in IOException('Failed to parse config resource: ' + configLocation). The root cause in the exception chain is the actual XML/D TD/property error.","triggerScenarios":"Setting configLocation on MybatisSqlSessionFactoryBean to a mybatis-config.xml that is malformed XML, references an undefined or missing properties file, uses invalid settings names, or contains unsupported element ordering.","commonSituations":"Hand-editing mybatis-config.xml and breaking tags; referencing classpath resources that moved; environment-specific config overlays; upgrading mybatis-plus where previously-tolerated settings become strict.","solutions":["Read the cause exception — MyBatis reports the exact element/attribute that failed; fix that line in the config file","Validate the XML is well-formed (IDE validation, xmllint) and matches the MyBatis configuration DTD","Check any <properties resource=...> references resolve on the classpath","Remove settings duplicated between configLocation XML and Java-side setters that conflict during parse"],"exampleFix":"<!-- before: typo in element -->\n<configuration>\n  <setting name=\"mapUnderscoreToCamelCase\" value=\"true\"/>\n</configuration>\n<!-- after -->\n<configuration>\n  <settings>\n    <setting name=\"mapUnderscoreToCamelCase\" value=\"true\"/>\n  </settings>\n</configuration>","handlingStrategy":"validation","validationCode":"// Validate mybatis-config.xml is well-formed before wiring it\nDocumentBuilderFactory f = DocumentBuilderFactory.newInstance();\nf.setFeature(\"http://apache.org/xml/features/disallow-doctype-decl\", false);\ntry (InputStream in = configLocation.getInputStream()) {\n    f.newDocumentBuilder().parse(in); // throws on malformed XML\n}","typeGuard":null,"tryCatchPattern":"try {\n    factory.getObject();\n} catch (IOException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to parse config resource:\")) {\n        throw new IllegalStateException(\"Invalid mybatis-config.xml: \" + e.getCause().getMessage(), e.getCause());\n    }\n    throw e;\n}","preventionTips":["Keep mybatis-config.xml under IDE XML validation and in code review scope","Run the app in CI before deploy so config parse errors surface early","Avoid splitting settings between XML and Java setters; pick one source of truth"],"tags":["mybatis-plus","spring","xml","configuration","startup"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}