binarywang/WxJava · error · WxRuntimeException

无法找到对应【%s】的小程序配置信息,请核实!

Error message

无法找到对应【%s】的小程序配置信息,请核实!

What it means

Thrown as WxRuntimeException when switchoverTo(miniAppId, func) cannot find a config for the given miniAppId in configMap, and the optional Function callback either returns null or was not provided. This method is used in multi-account MiniApp management to switch the active config context.

Source

Thrown at weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java:598

    return switchoverTo(miniAppId, null);
  }

  @Override
  public WxMaService switchoverTo(String miniAppId, Function<String, WxMaConfig> func) {
    if (this.configMap.containsKey(miniAppId)) {
      WxMaConfigHolder.set(miniAppId);
      return this;
    }

    if (func != null) {
      WxMaConfig config = func.apply(miniAppId);
      if (config != null) {
        this.addConfig(miniAppId, config);
        return this;
      }
    }

    throw new WxRuntimeException(String.format("无法找到对应【%s】的小程序配置信息,请核实!", miniAppId));
  }

  @Override
  public boolean switchover(String mpId) {
    if (this.configMap.containsKey(mpId)) {
      WxMaConfigHolder.set(mpId);
      return true;
    }

    log.error("无法找到对应【{}】的小程序配置信息,请核实!", mpId);
    return false;
  }

  @Override
  public void setRetrySleepMillis(int retrySleepMillis) {
    this.retrySleepMillis = retrySleepMillis;
  }

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Register the config before switching: maService.addConfig(miniAppId, config) then maService.switchoverTo(miniAppId)
  2. Use switchover(mpId) which returns boolean false instead of throwing
  3. Verify the miniAppId string exactly matches what was registered (case-sensitive)
  4. If using a func callback, ensure it returns a non-null WxMaConfig for valid IDs

Example fix

// before
maService.switchoverTo("wxWrongId", id -> null);

// after
maService.addConfig("wxCorrectId", wxMaConfig);
maService.switchoverTo("wxCorrectId");
Defensive patterns

Strategy: validation

Validate before calling

// Check if config exists before calling switchoverTo
if (!maService.getConfigMap().containsKey(miniAppId)) {
  // register it first, or use the non-throwing switchover() method
  if (!maService.switchover(miniAppId)) {
    log.warn("No config for miniAppId: {}", miniAppId);
    return;
  }
}

Type guard

private boolean isAppRegistered(WxMaService service, String appId) {
  return service.switchover(appId); // returns boolean, does not throw
}

Try / catch

try {
  maService.switchoverTo(miniAppId);
} catch (WxRuntimeException e) {
  if (e.getMessage().contains("无法找到对应")) {
    log.error("MiniApp config not found for: {}", miniAppId);
    // dynamically load config or skip
  } else {
    throw e;
  }
}

Prevention

When it happens

Trigger: Calling switchoverTo('wxAbc123', func) when 'wxAbc123' is not in configMap AND func.apply('wxAbc123') returns null, or calling switchoverTo('wxAbc123') (no func) when the ID is unregistered.

Common situations: Typo in app ID; app not registered via addConfig() before switching; dynamic loader function fails to produce a config (e.g., database lookup returns null); multi-tenant setup where app ID comes from untrusted user input.

Related errors


AI-assisted analysis of binarywang/WxJava@1c43293a3c (2026-08-14). Data as JSON: /api/errors/b247251d7a63d3f2. Report an issue: GitHub.