mybatis/mybatis-3 · error · ExecutorException
Cannot get Configuration as factory method [" + this.configu
Error message
Cannot get Configuration as factory method [" + this.configurationFactory + "]#[" + FACTORY_METHOD + "] is not static."
What it means
Thrown while rebuilding a Configuration for a deserialized lazy object: the configured configurationFactory class has a method named getConfiguration (the required FACTORY_METHOD), but it is an instance method. MyBatis can only call it reflectively with no receiver, so the method must be static.
Source
Thrown at src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java:234
if (this.serializationCheck == null) {
final ResultLoader old = this.resultLoader;
this.resultLoader = new ResultLoader(old.configuration, new ClosedExecutor(), old.mappedStatement,
old.parameterObject, old.targetType, old.cacheKey, old.boundSql);
}
this.metaResultObject.setValue(property, this.resultLoader.loadResult());
}
private Configuration getConfiguration() {
if (this.configurationFactory == null) {
throw new ExecutorException("Cannot get Configuration as configuration factory was not set.");
}
Object configurationObject;
try {
final Method factoryMethod = this.configurationFactory.getDeclaredMethod(FACTORY_METHOD);
if (!Modifier.isStatic(factoryMethod.getModifiers())) {
throw new ExecutorException("Cannot get Configuration as factory method [" + this.configurationFactory + "]#["
+ 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) {View on GitHub (pinned to 008069adb1)
Solutions
- Make the factory method static: public static Configuration getConfiguration() { return ...; }
- Have that static method delegate to a well-known singleton holding the SqlSessionFactory
- Rebuild and redeploy so the reflective lookup sees the corrected class
Example fix
// before
public class MyConfigFactory {
public Configuration getConfiguration() { return cfg; } // instance method
}
// after
public class MyConfigFactory {
public static Configuration getConfiguration() { return App.sqlSessionFactory.getConfiguration(); }
} Defensive patterns
Strategy: validation
Validate before calling
// Smoke-test the factory once at boot
Method m = MyConfigFactory.class.getDeclaredMethod("getConfiguration");
if (!Modifier.isStatic(m.getModifiers())) throw new IllegalStateException("getConfiguration must be static"); Try / catch
try { MyConfigFactory.getConfiguration(); } catch (Exception e) { fail deployment with clear message } // surfaces 122/123 at deploy time, not at first lazy load Prevention
- Standardize one factory class per application and review it like production code
- Add a unit test asserting the method exists and is static
- Never let the factory depend on instance state
When it happens
Trigger: LoadPair.getConfiguration() runs after deserialization, configurationFactory is set, getDeclaredMethod("getConfiguration") succeeds, but Modifier.isStatic(factoryMethod.getModifiers()) is false.
Common situations: Developer writes a factory class with a non-static getConfiguration() method; refactoring a static factory into an instance method; copy-paste factory implementations that rely on instance state.
Related errors
- Cannot get Configuration as factory class [" + this.configur
- 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/507ad8e188d333d5.
Report an issue: GitHub.