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 + "] threw an exception."
What it means
Thrown when the factory method itself blows up while MyBatis rebuilds the Configuration for a deserialized lazy object. The privileged invocation path (factory method not publicly accessible, so it is invoked inside AccessController.doPrivileged) throws a PrivilegedActionException; MyBatis unwraps ex.getCause() and reports it as the reason getConfiguration() failed.
Source
Thrown at src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java:256
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);
}
private Log getLogger() {
if (this.log == null) {
this.log = LogFactory.getLog(this.getClass());View on GitHub (pinned to 008069adb1)
Solutions
- Read the cause chain: the reported cause exception is thrown by your getConfiguration() body — fix that (usually an uninitialized singleton)
- Make the factory lazily build/caching the SqlSessionFactory instead of depending on startup order
- Initialize the factory before any deserialized lazy object is touched (e.g. ServletContextListener before session deserialization)
Example fix
// before
public static Configuration getConfiguration() {
return AppContext.getBean(SqlSessionFactory.class).getConfiguration(); // AppContext null early
}
// after
private static volatile Configuration cached;
public static Configuration getConfiguration() {
if (cached == null) cached = buildFactory().getConfiguration();
return cached;
} Defensive patterns
Strategy: try-catch
Validate before calling
// Call the factory during startup; any user-code exception surfaces immediately Configuration cfg = MyConfigFactory.getConfiguration(); assert cfg != null;
Try / catch
try { lazy.getProp(); } catch (ExecutorException e) { Throwable cause = e.getCause(); // the factory's own exception log and fix cause; rethrow; } Prevention
- Initialize the Configuration before exposing the app to serialized objects
- Make the factory lazy-caching and null-safe
- Cluster nodes must complete bootstrap before deserializing sessions
When it happens
Trigger: LoadPair.getConfiguration() calls the static getConfiguration() of configurationFactory through setAccessible(true)/invoke inside a privileged block, and the method throws (NPE on an uninitialized singleton, class not found during the call, IllegalAccess on invoke).
Common situations: Factory method dereferences a static field that is still null at deserialization time (e.g. framework not yet initialized); factory delegating to a Spring context that is not ready; the exception cause shown is the user's own bug inside getConfiguration().
Related errors
- Cannot get Configuration as factory method [" + this.configu
- Cannot get Configuration as factory class [" + this.configur
- Error creating instance. Cause: {cause}
- Error in result map '{resultMapId}'. Failed to find a constr
- Failed to create a new Configuration instance.
AI-assisted analysis of mybatis/mybatis-3@008069adb1 (2026-08-14).
Data as JSON: /api/errors/613e3fb443d016df.
Report an issue: GitHub.