{"record":{"id":"002c76be6862b920","repo":"mybatis/mybatis-3","slug":"no-environment-specified","errorCode":null,"errorMessage":"No environment specified.","messagePattern":"No environment specified\\.","errorType":"validation","errorClass":"BuilderException","httpStatus":null,"severity":"error","filePath":"src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java","lineNumber":427,"sourceCode":"          try (InputStream inputStream = Resources.getUrlAsStream(url)) {\n            XMLMapperBuilder mapperParser = new XMLMapperBuilder(inputStream, configuration, url,\n                configuration.getSqlFragments());\n            mapperParser.parse();\n          }\n        } else if (resource == null && url == null && mapperClass != null) {\n          Class<?> mapperInterface = Resources.classForName(mapperClass);\n          configuration.addMapper(mapperInterface);\n        } else {\n          throw new BuilderException(\n              \"A mapper element may only specify a url, resource or class, but not more than one.\");\n        }\n      }\n    }\n  }\n\n  private boolean isSpecifiedEnvironment(String id) {\n    if (environment == null) {\n      throw new BuilderException(\"No environment specified.\");\n    }\n    if (id == null) {\n      throw new BuilderException(\"Environment requires an id attribute.\");\n    }\n    return environment.equals(id);\n  }\n\n  private static Configuration newConfig(Class<? extends Configuration> configClass) {\n    try {\n      return configClass.getDeclaredConstructor().newInstance();\n    } catch (Exception ex) {\n      throw new BuilderException(\"Failed to create a new Configuration instance.\", ex);\n    }\n  }\n\n}\n","sourceCodeStart":409,"sourceCodeEnd":444,"githubUrl":"https://github.com/mybatis/mybatis-3/blob/008069adb1b089579b5dcba87ee591908b263274/src/main/java/org/apache/ibatis/builder/xml/XMLConfigBuilder.java#L409-L444","documentation":"Thrown by XMLConfigBuilder.isSpecifiedEnvironment() while parsing <environments> in mybatis-config.xml. The field 'environment' holds the value of the default attribute of the <environments> element; when it is null the builder cannot decide which environment applies, so it refuses to continue. Every <environment id=\"...\"> child is validated against that default.","triggerScenarios":"<environments> element present with <environment> children but the default attribute is missing, e.g. <environments>...</environments> with no default=\"development\"; also when the default attribute value is empty. Thrown during SqlSessionFactoryBuilder.build().","commonSituations":"Hand-editing mybatis-config.xml and dropping the default attribute; merging config files during refactoring; tutorials that show only one environment and omit default, which fails on strict versions.","solutions":["Add default=\"<envId>\" to the <environments> element matching the id of one child <environment id=\"...\">","If you build Configuration programmatically, call config.setEnvironment(...) instead of relying on XML","Check for stray whitespace/empty value in the default attribute"],"exampleFix":"<!-- before -->\n<environments>\n  <environment id=\"development\">...</environment>\n</environments>\n\n<!-- after -->\n<environments default=\"development\">\n  <environment id=\"development\">...</environment>\n</environments>","handlingStrategy":"validation","validationCode":"String def = environmentsElement.getAttribute(\"default\");\nif (def == null || def.isEmpty()) throw new IllegalStateException(\"<environments> requires default=...\");\nboolean matches = Stream.of(environmentChildren).anyMatch(c -> def.equals(c.getAttribute(\"id\")));\nif (!matches) throw new IllegalStateException(\"default environment '\" + def + \"' has no matching <environment id>\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always set default= on <environments>","Keep one canonical config template with environments pre-filled"],"tags":["mybatis","xml-config","environment"],"backgroundTag":null,"analyzedSha":"008069adb1b089579b5dcba87ee591908b263274","analyzedAt":"2026-08-14T13:07:10.264Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}