{"record":{"id":"a07b8b1cd2237390","repo":"mybatis/mybatis-3","slug":"cannot-get-configuration-as-factory-class-thi","errorCode":null,"errorMessage":"Cannot get Configuration as factory class [\" + this.configurationFactory + \"] is missing factory method of name [\" + FACTORY_METHOD + \"].\"","messagePattern":"Cannot get Configuration as factory class \\[\" \\+ this\\.configurationFactory \\+ \"\\] is missing factory method of name \\[\" \\+ FACTORY_METHOD \\+ \"\\]\\.\"","errorType":"exception","errorClass":"ExecutorException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java","lineNumber":253,"sourceCode":"              + FACTORY_METHOD + \"] is not static.\");\n        }\n\n        if (!factoryMethod.canAccess(null)) {\n          configurationObject = AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {\n            try {\n              factoryMethod.setAccessible(true);\n              return factoryMethod.invoke(null);\n            } finally {\n              factoryMethod.setAccessible(false);\n            }\n          });\n        } else {\n          configurationObject = factoryMethod.invoke(null);\n        }\n      } catch (final ExecutorException ex) {\n        throw ex;\n      } catch (final NoSuchMethodException ex) {\n        throw new ExecutorException(\"Cannot get Configuration as factory class [\" + this.configurationFactory\n            + \"] is missing factory method of name [\" + FACTORY_METHOD + \"].\", ex);\n      } catch (final PrivilegedActionException ex) {\n        throw new ExecutorException(\"Cannot get Configuration as factory method [\" + this.configurationFactory + \"]#[\"\n            + FACTORY_METHOD + \"] threw an exception.\", ex.getCause());\n      } catch (final Exception ex) {\n        throw new ExecutorException(\"Cannot get Configuration as factory method [\" + this.configurationFactory + \"]#[\"\n            + FACTORY_METHOD + \"] threw an exception.\", ex);\n      }\n\n      if (!(configurationObject instanceof Configuration)) {\n        throw new ExecutorException(\"Cannot get Configuration as factory method [\" + this.configurationFactory + \"]#[\"\n            + FACTORY_METHOD + \"] didn't return [\" + Configuration.class + \"] but [\"\n            + (configurationObject == null ? \"null\" : configurationObject.getClass()) + \"].\");\n      }\n\n      return Configuration.class.cast(configurationObject);\n    }\n","sourceCodeStart":235,"sourceCodeEnd":271,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java#L235-L271","documentation":"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.","triggerScenarios":"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).","commonSituations":"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.","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"],"exampleFix":"// before\npublic class ConfigHolder {\n  public static SqlSessionFactory getSessionFactory() { return factory; }\n}\n// after\npublic class ConfigHolder {\n  public static SqlSessionFactory getSessionFactory() { return factory; }\n  public static Configuration getConfiguration() { return factory.getConfiguration(); }\n}","handlingStrategy":"validation","validationCode":"try { MyConfigFactory.class.getDeclaredMethod(\"getConfiguration\"); } catch (NoSuchMethodException e) { throw new IllegalStateException(\"Factory missing static getConfiguration()\", e); }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["mybatis","lazy-loading","reflection","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}