baomidou/mybatis-plus · error · IllegalArgumentException

%s does not contain value for %s

Error message

%s does not contain value for %s

What it means

Thrown by StrictMap.get when a lookup key maps to null. StrictMap deliberately fails fast on unknown statement/result-map/parameter-map ids instead of returning null, so typos in statement ids surface at configuration access time with the map name and the missing key in the message.

Source

Thrown at mybatis-plus-core/src/main/java/com/baomidou/mybatisplus/core/MybatisConfiguration.java:482

                    }
                }
            }
            return super.put(key, value);
        }

        @Override
        public boolean containsKey(Object key) {
            if (key == null) {
                return false;
            }
            return super.get(key) != null;
        }

        @Override
        public V get(Object key) {
            V value = super.get(key);
            if (value == null) {
                throw new IllegalArgumentException(name + " does not contain value for " + key);
            }
            if (useGeneratedShortKey && AMBIGUITY_INSTANCE == value) {
                throw new IllegalArgumentException(key + " is ambiguous in " + name
                    + " (try using the full name including the namespace, or rename one of the entries)");
            }
            return value;
        }

        private String getShortName(String key) {
            final String[] keyParts = key.split("\\.");
            return keyParts[keyParts.length - 1];
        }
    }
}

View on GitHub (pinned to bf67d90747)

Solutions

  1. Verify the statement id in the error exists: check the mapper XML <select id="..."> matches the interface method name exactly (case-sensitive).
  2. Ensure the mapper XML is actually loaded: check mybatis-plus.mapper-locations (e.g. classpath*:mapper/**/*.xml) in application.yml, or the <mapper> entry in mybatis-config.xml.
  3. If using pure annotation mappers, confirm the method has a statement annotation (@Select, @Insert, @Update, @Delete) or is a MyBatis-Plus BaseMapper inherited method.
  4. Check the namespace attribute of the XML equals the fully-qualified interface name.

Example fix

# before: mapper XML not scanned
mybatis-plus:
  mapper-locations: classpath:mapper/*.xml   # file actually in com/example/mapper/

# after
mybatis-plus:
  mapper-locations: classpath*:**/mapper/*.xml
Defensive patterns

Strategy: validation

Validate before calling

// verify a statement id is registered before use
String id = "com.example.UserMapper.selectById";
if (!factory.getConfiguration().hasStatement(id, false)) {
    throw new IllegalStateException("Unknown statement: " + id);
}

Try / catch

Catch IllegalArgumentException from StrictMap lookup only at configuration/diagnostic boundaries; log the missing key and fix the mapping — retrying is pointless because configuration is immutable.

Prevention

When it happens

Trigger: Calling sqlSession.getMapper(...).someMethod() where the method's statement id was never registered (annotation missing and no XML statement); looking up a result map or sql fragment by an id that does not exist; using a statement id with a misspelled namespace or method name.

Common situations: Mapper interface method has no @Select/@Insert annotation and no matching XML statement; XML mapper file not listed in <mappers> or not in the mapper-locations scan path; renaming a Java method without updating the XML id; the MyBatis-Plus mapper-locations glob not matching the actual XML location.

Related errors


AI-assisted analysis of baomidou/mybatis-plus@bf67d90747 (2026-08-14). Data as JSON: /api/errors/555a12ac015d45fa. Report an issue: GitHub.