mybatis/mybatis-3 · error · ExecutorException
Cannot get Configuration as factory class [" + this.configur
Error message
Cannot get Configuration as factory class [" + this.configurationFactory + "] is missing factory method of name [" + FACTORY_METHOD + "]."
What it means
Thrown when the configurationFactory class does not declare a method named getConfiguration at all. During lazy-load recovery after deserialization, MyBatis reflectively looks up getDeclaredMethod("getConfiguration") on the factory class; a NoSuchMethodException is wrapped into this ExecutorException naming the offending class and the required method name.
Source
Thrown at src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java:253
+ FACTORY_METHOD + "] is not static.");
}
if (!factoryMethod.canAccess(null)) {
configurationObject = AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
try {
factoryMethod.setAccessible(true);
return factoryMethod.invoke(null);
} finally {
factoryMethod.setAccessible(false);
}
});
} else {
configurationObject = factoryMethod.invoke(null);
}
} catch (final ExecutorException ex) {
throw ex;
} catch (final NoSuchMethodException ex) {
throw new ExecutorException("Cannot get Configuration as factory class [" + this.configurationFactory
+ "] is missing factory method of name [" + FACTORY_METHOD + "].", ex);
} catch (final PrivilegedActionException ex) {
throw new ExecutorException("Cannot get Configuration as factory method [" + this.configurationFactory + "]#["
+ FACTORY_METHOD + "] threw an exception.", ex.getCause());
} catch (final Exception ex) {
throw new ExecutorException("Cannot get Configuration as factory method [" + this.configurationFactory + "]#["
+ FACTORY_METHOD + "] threw an exception.", ex);
}
if (!(configurationObject instanceof Configuration)) {
throw new ExecutorException("Cannot get Configuration as factory method [" + this.configurationFactory + "]#["
+ FACTORY_METHOD + "] didn't return [" + Configuration.class + "] but ["
+ (configurationObject == null ? "null" : configurationObject.getClass()) + "].");
}
return Configuration.class.cast(configurationObject);
}
View on GitHub (pinned to 008069adb1)
Solutions
- Add public static Configuration getConfiguration() to the class named in the message
- Check the FQCN in the configurationFactory setting for typos and stale package names
- Prefer a dedicated tiny factory class over reusing arbitrary application classes
Example fix
// before
public class ConfigHolder {
public static SqlSessionFactory getSessionFactory() { return factory; }
}
// after
public class ConfigHolder {
public static SqlSessionFactory getSessionFactory() { return factory; }
public static Configuration getConfiguration() { return factory.getConfiguration(); }
} Defensive patterns
Strategy: validation
Validate before calling
try { MyConfigFactory.class.getDeclaredMethod("getConfiguration"); } catch (NoSuchMethodException e) { throw new IllegalStateException("Factory missing static getConfiguration()", e); } Prevention
- Keep the factory under the same package as config bootstrap code so renames are caught by compile
- Boot-time reflection check in a unit test
- Use a dedicated factory class, not an arbitrary application class
When it happens
Trigger: LoadPair.getConfiguration() after deserialization; configurationFactory points to a class lacking any getConfiguration() method (wrong class, typo in the setting, or an older factory without the method).
Common situations: Typo in the configurationFactory FQCN resolving to a different class; pointing configurationFactory at a helper class that stores the SqlSessionFactory but exposes a differently named getter; upgrading a codebase where the factory convention was not followed.
Related errors
- Cannot get Configuration as factory method [" + this.configu
- Error creating instance. Cause: {cause}
- Cannot lazy load property [" + this.property + "] of deseria
- Cannot get Configuration as configuration factory was not se
- Cannot get Configuration as factory method [" + this.configu
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/a07b8b1cd2237390.
Report an issue: GitHub.