binarywang/WxJava · error · RuntimeException

请确保微信公众号配置 appId 的唯一性

Error message

请确保微信公众号配置 appId 的唯一性

What it means

Thrown by the Solon multi-account MiniProgram (小程序) auto-configuration when two tenants resolve to the same appId, to prevent Redis token/ticket cache collisions. NOTE: the message string literally says "微信公众号" (Official Account) even though this is the miniapp module — a copy-paste bug in the message text; treat it as the miniapp appId-uniqueness error.

Source

Thrown at solon-plugins/wx-java-miniapp-multi-solon-plugin/src/main/java/com/binarywang/solon/wxjava/miniapp/configuration/services/AbstractWxMaConfiguration.java:53

    Map<String, WxMaSingleProperties> appsMap = wxMaMultiProperties.getApps();
    if (appsMap == null || appsMap.isEmpty()) {
      log.warn("微信公众号应用参数未配置,通过 WxMaMultiServices#getWxMaService(\"tenantId\")获取实例将返回空");
      return new WxMaMultiServicesImpl();
    }
    /**
     * 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。
     *
     * 查看 {@link cn.binarywang.wx.miniapp.config.impl.WxMaRedisConfigImpl#setAppId(String)}
     */
    Collection<WxMaSingleProperties> apps = appsMap.values();
    if (apps.size() > 1) {
      // 校验 appId 是否唯一
      boolean multi = apps.stream()
        // 没有 appId,如果不判断是否为空,这里会报 NPE 异常
        .collect(Collectors.groupingBy(c -> c.getAppId() == null ? 0 : c.getAppId(), Collectors.counting()))
        .entrySet().stream().anyMatch(e -> e.getValue() > 1);
      if (multi) {
        throw new RuntimeException("请确保微信公众号配置 appId 的唯一性");
      }
    }
    WxMaMultiServicesImpl services = new WxMaMultiServicesImpl();

    Set<Map.Entry<String, WxMaSingleProperties>> entries = appsMap.entrySet();
    for (Map.Entry<String, WxMaSingleProperties> entry : entries) {
      String tenantId = entry.getKey();
      WxMaSingleProperties wxMaSingleProperties = entry.getValue();
      WxMaDefaultConfigImpl storage = this.wxMaConfigStorage(wxMaMultiProperties);
      this.configApp(storage, wxMaSingleProperties);
      this.configHttp(storage, wxMaMultiProperties.getConfigStorage());
      WxMaService wxMaService = this.wxMaService(storage, wxMaMultiProperties);
      services.addWxMaService(tenantId, wxMaService);
    }
    return services;
  }

  /**

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Recognize this is the MINIAPP config despite the message wording; open `wxjava.mini.apps`.
  2. Give each tenant a distinct mini-program `appId`.
  3. Fill in any blank appIds; restart.

Example fix

// before
wxjava:
  miniapp:
    apps:
      t1: { appId: wxmini001 }
      t2: { appId: wxmini001 }  # throws (message wrongly says 公众号)
// after
      t2: { appId: wxmini002 }
Defensive patterns

Strategy: validation

Validate before calling

// Miniapp: validate appId uniqueness (note: message text wrongly says 公众号)
Set<String> seen = new HashSet<>();
for (WxMaSingleProperties p : appsMap.values()) {
    String id = p.getAppId();
    if (id == null || !seen.add(id)) {
        throw new IllegalStateException("Miniapp appId missing or duplicated: " + id);
    }
}

Prevention

When it happens

Trigger: Two entries under `wxjava.miniapp.apps.*` with the same `appId`, or two entries both with null appId (null is collapsed to key `0`).

Common situations: Same appId reused for two mini-program tenant blocks; appId left blank on multiple entries; being misled by the wrong product name in the message and looking in the MP config instead of the miniapp config.

Related errors


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