MyCATApache/Mycat-Server · error · ConfigException

elements length over one!

Error message

${tagName} elements length over one!

What it means

ConfigUtil.loadBean requires exactly one XML element with the given tag name. When getElementsByTagName finds more than one, it throws ConfigException before delegating to loadBean(Element). Unlike loadElement it does not check for zero matches, so only the 'more than one' case throws here.

Solutions

  1. Remove or consolidate the duplicate '<tagName>' elements in the XML so exactly one remains
  2. Remember bean definitions cannot be repeated to override — edit the single existing bean instead
  3. If multiple beans are needed, use the collection-loading API (loadBeans/map variant) rather than loadBean

Example fix

<!-- before -->
<bean name="db1" .../><bean name="db1" .../>
<!-- after -->
<bean name="db1" .../>  <!-- single definition -->
Defensive patterns

Strategy: validation

Validate before calling

NodeList nl = parent.getElementsByTagName(tagName);
if (nl.getLength() > 1) throw new ConfigException("multiple <" + tagName + "> beans defined");

Try / catch

try { BeanConfig b = ConfigUtil.loadBean(parent, tag); } catch (ConfigException e) { log.error("duplicate bean <{}>; edit the single definition", tag); throw e; }

Prevention

When it happens

Trigger: Calling loadBean(parent, tagName) where the XML contains 2+ elements with that tag, e.g. two <connection> or two <property>-holder blocks under one parent.

Common situations: Duplicated bean definitions in mycat XML config after merges or scripted config generation; repeating a bean stanza intending to override it instead of adding a second one.

Understand the failure class

Background: Schema validation failed / invalid input schema: payload rejected because its shape doesn't match the expected schema — this error's family across 28 libraries.

Related errors


AI-assisted analysis of MyCATApache/Mycat-Server@65f8d8beb7 (2026-09-11). Data as JSON: /api/errors/f1db3d670035dfe1. Report an issue: GitHub.

Appendix: source

Thrown at src/main/java/io/mycat/config/util/ConfigUtil.java:175

                if ("property".equals(name)) {
                    String key = e.getAttribute("name");
                    NodeList nl = e.getElementsByTagName("bean");
                    if (nl.getLength() == 0) {
                        String value = e.getTextContent();
                        map.put(key, StringUtil.isEmpty(value) ? null : value.trim());
                    } else {
                        map.put(key, loadBean((Element) nl.item(0)));
                    }
                }
            }
        }
        return map;
    }

    public static BeanConfig loadBean(Element parent, String tagName) {
        NodeList nodeList = parent.getElementsByTagName(tagName);
        if (nodeList.getLength() > 1) {
            throw new ConfigException(tagName + " elements length over one!");
        }
        return loadBean((Element) nodeList.item(0));
    }

    public static BeanConfig loadBean(Element e) {
        if (e == null) {
            return null;
        }
        BeanConfig bean = new BeanConfig();
        bean.setName(e.getAttribute("name"));
        Element element = loadElement(e, "className");
        if (element != null) {
            bean.setClassName(element.getTextContent());
        } else {
            bean.setClassName(e.getAttribute("class"));
        }
        bean.setParams(loadElements(e));
        return bean;

View on GitHub (pinned to 65f8d8beb7)