{"record":{"id":"507ad8e188d333d5","repo":"mybatis/mybatis-3","slug":"cannot-get-configuration-as-factory-method-th","errorCode":null,"errorMessage":"Cannot get Configuration as factory method [\" + this.configurationFactory + \"]#[\" + FACTORY_METHOD + \"] is not static.\"","messagePattern":"Cannot get Configuration as factory method \\[\" \\+ this\\.configurationFactory \\+ \"\\]#\\[\" \\+ FACTORY_METHOD \\+ \"\\] is not static\\.\"","errorType":"exception","errorClass":"ExecutorException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java","lineNumber":234,"sourceCode":"      if (this.serializationCheck == null) {\n        final ResultLoader old = this.resultLoader;\n        this.resultLoader = new ResultLoader(old.configuration, new ClosedExecutor(), old.mappedStatement,\n            old.parameterObject, old.targetType, old.cacheKey, old.boundSql);\n      }\n\n      this.metaResultObject.setValue(property, this.resultLoader.loadResult());\n    }\n\n    private Configuration getConfiguration() {\n      if (this.configurationFactory == null) {\n        throw new ExecutorException(\"Cannot get Configuration as configuration factory was not set.\");\n      }\n\n      Object configurationObject;\n      try {\n        final Method factoryMethod = this.configurationFactory.getDeclaredMethod(FACTORY_METHOD);\n        if (!Modifier.isStatic(factoryMethod.getModifiers())) {\n          throw new ExecutorException(\"Cannot get Configuration as factory method [\" + this.configurationFactory + \"]#[\"\n              + 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) {","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/executor/loader/ResultLoaderMap.java#L216-L252","documentation":"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.","triggerScenarios":"LoadPair.getConfiguration() runs after deserialization, configurationFactory is set, getDeclaredMethod(\"getConfiguration\") succeeds, but Modifier.isStatic(factoryMethod.getModifiers()) is false.","commonSituations":"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.","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"],"exampleFix":"// before\npublic class MyConfigFactory {\n  public Configuration getConfiguration() { return cfg; } // instance method\n}\n// after\npublic class MyConfigFactory {\n  public static Configuration getConfiguration() { return App.sqlSessionFactory.getConfiguration(); }\n}","handlingStrategy":"validation","validationCode":"// Smoke-test the factory once at boot\nMethod m = MyConfigFactory.class.getDeclaredMethod(\"getConfiguration\");\nif (!Modifier.isStatic(m.getModifiers())) throw new IllegalStateException(\"getConfiguration must be static\");","typeGuard":null,"tryCatchPattern":"try { MyConfigFactory.getConfiguration(); } catch (Exception e) { fail deployment with clear message } // surfaces 122/123 at deploy time, not at first lazy load","preventionTips":["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"],"tags":["mybatis","lazy-loading","reflection","configuration"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}