{"record":{"id":"9e897f8a211b9942","repo":"baomidou/mybatis-plus","slug":"the-properties-element-cannot-specify-both-a-url-a","errorCode":null,"errorMessage":"The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.","messagePattern":"The properties element cannot specify both a URL and a resource based property file reference\\.  Please specify one or the other\\.","errorType":"exception","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLConfigBuilder.java","lineNumber":246,"sourceCode":"    }\n\n    private void reflectorFactoryElement(XNode context) throws Exception {\n        if (context != null) {\n            String type = context.getStringAttribute(\"type\");\n            ReflectorFactory factory = (ReflectorFactory) resolveClass(type).getDeclaredConstructor().newInstance();\n            configuration.setReflectorFactory(factory);\n        }\n    }\n\n    private void propertiesElement(XNode context) throws Exception {\n        if (context == null) {\n            return;\n        }\n        Properties defaults = context.getChildrenAsProperties();\n        String resource = context.getStringAttribute(\"resource\");\n        String url = context.getStringAttribute(\"url\");\n        if (resource != null && url != null) {\n            throw new BuilderException(\n                \"The properties element cannot specify both a URL and a resource based property file reference.  Please specify one or the other.\");\n        }\n        if (resource != null) {\n            defaults.putAll(Resources.getResourceAsProperties(resource));\n        } else if (url != null) {\n            defaults.putAll(Resources.getUrlAsProperties(url));\n        }\n        Properties vars = configuration.getVariables();\n        if (vars != null) {\n            defaults.putAll(vars);\n        }\n        parser.setVariables(defaults);\n        configuration.setVariables(defaults);\n    }\n\n    private void settingsElement(Properties props) {\n        configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty(\"autoMappingBehavior\", \"PARTIAL\")));\n        configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty(\"autoMappingUnknownColumnBehavior\", \"NONE\")));","sourceCodeStart":228,"sourceCodeEnd":264,"githubUrl":"https://github.com/baomidou/mybatis-plus/blob/bf67d907478c724120bf76292da54abf9e73c2b3/mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLConfigBuilder.java#L228-L264","documentation":"Thrown by propertiesElement when the <properties> element in mybatis-config.xml declares both a resource attribute and a url attribute. MyBatis can load external properties from exactly one source per element — a classpath resource or a URL — and refuses the ambiguous combination rather than guessing precedence.","triggerScenarios":"<properties resource=\"db.properties\" url=\"file:///etc/app/db.properties\"> in mybatis-config.xml, with both attributes present.","commonSituations":"Migrating from file-based to classpath-based property files and leaving the old attribute; merging config snippets from different environments where one used resource and the other url.","solutions":["Keep only the attribute matching where the file lives: resource for classpath files, url for absolute/file/remote URLs.","If both sources are genuinely needed, load one into the other (e.g. import inside the properties file) or merge them into a single file.","In Spring Boot, prefer externalizing via application.yml/property sources instead of the MyBatis <properties> element."],"exampleFix":"<!-- before -->\n<properties resource=\"db.properties\" url=\"file:///etc/app/db.properties\"/>\n\n<!-- after -->\n<properties resource=\"db.properties\"/>","handlingStrategy":"validation","validationCode":"// lint the <properties> element before build\ntry (InputStream in = Resources.getResourceAsStream(\"mybatis-config.xml\")) {\n    javax.xml.parsers.Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance()\n        .newDocumentBuilder().parse(in);\n    org.w3c.dom.NodeList nl = doc.getElementsByTagName(\"properties\");\n    for (int i = 0; i < nl.getLength(); i++) {\n        org.w3c.dom.Element el = (org.w3c.dom.Element) nl.item(i);\n        if (el.hasAttribute(\"resource\") && el.hasAttribute(\"url\"))\n            throw new IllegalStateException(\"<properties> has both resource and url\");\n    }\n}","typeGuard":null,"tryCatchPattern":"Catch BuilderException about 'both a URL and a resource'; delete one attribute per the message and rebuild.","preventionTips":["Pick one property-source convention per project.","Prefer Spring's property sources over the MyBatis <properties> element in boot apps."],"tags":["mybatis","mybatis-plus","xml-config","properties","configuration"],"backgroundTag":null,"analyzedSha":"bf67d907478c724120bf76292da54abf9e73c2b3","analyzedAt":"2026-08-14T15:17:09.543Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}