baomidou/mybatis-plus · error · BuilderException
The properties element cannot specify both a URL and a resou
Error message
The properties element cannot specify both a URL and a resource based property file reference. Please specify one or the other.
What it means
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.
Source
Thrown at mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisXMLConfigBuilder.java:246
}
private void reflectorFactoryElement(XNode context) throws Exception {
if (context != null) {
String type = context.getStringAttribute("type");
ReflectorFactory factory = (ReflectorFactory) resolveClass(type).getDeclaredConstructor().newInstance();
configuration.setReflectorFactory(factory);
}
}
private void propertiesElement(XNode context) throws Exception {
if (context == null) {
return;
}
Properties defaults = context.getChildrenAsProperties();
String resource = context.getStringAttribute("resource");
String url = context.getStringAttribute("url");
if (resource != null && url != null) {
throw new BuilderException(
"The properties element cannot specify both a URL and a resource based property file reference. Please specify one or the other.");
}
if (resource != null) {
defaults.putAll(Resources.getResourceAsProperties(resource));
} else if (url != null) {
defaults.putAll(Resources.getUrlAsProperties(url));
}
Properties vars = configuration.getVariables();
if (vars != null) {
defaults.putAll(vars);
}
parser.setVariables(defaults);
configuration.setVariables(defaults);
}
private void settingsElement(Properties props) {
configuration.setAutoMappingBehavior(AutoMappingBehavior.valueOf(props.getProperty("autoMappingBehavior", "PARTIAL")));
configuration.setAutoMappingUnknownColumnBehavior(AutoMappingUnknownColumnBehavior.valueOf(props.getProperty("autoMappingUnknownColumnBehavior", "NONE")));View on GitHub (pinned to bf67d90747)
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.
Example fix
<!-- before --> <properties resource="db.properties" url="file:///etc/app/db.properties"/> <!-- after --> <properties resource="db.properties"/>
Defensive patterns
Strategy: validation
Validate before calling
// lint the <properties> element before build
try (InputStream in = Resources.getResourceAsStream("mybatis-config.xml")) {
javax.xml.parsers.Document doc = javax.xml.parsers.DocumentBuilderFactory.newInstance()
.newDocumentBuilder().parse(in);
org.w3c.dom.NodeList nl = doc.getElementsByTagName("properties");
for (int i = 0; i < nl.getLength(); i++) {
org.w3c.dom.Element el = (org.w3c.dom.Element) nl.item(i);
if (el.hasAttribute("resource") && el.hasAttribute("url"))
throw new IllegalStateException("<properties> has both resource and url");
}
} Try / catch
Catch BuilderException about 'both a URL and a resource'; delete one attribute per the message and rebuild.
Prevention
- Pick one property-source convention per project.
- Prefer Spring's property sources over the MyBatis <properties> element in boot apps.
When it happens
Trigger: <properties resource="db.properties" url="file:///etc/app/db.properties"> in mybatis-config.xml, with both attributes present.
Common situations: 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.
Related errors
- Error parsing SQL Mapper Configuration. Cause: %s
- A mapper element may only specify a url, resource or class,
- Environment requires an id attribute.
- %s already contains value for %s
- %s does not contain value for %s
AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14).
Data as JSON: /api/errors/9e897f8a211b9942.
Report an issue: GitHub.