binarywang/WxJava · error · RuntimeException

请确保微信开放平台配置 appId 的唯一性

Error message

请确保微信开放平台配置 appId 的唯一性

What it means

Thrown by the Spring Boot multi-account Open Platform (开放平台) starter when two tenants resolve to the same component appId, to avoid Redis token cache collisions. Unlike the other starters it uses a string placeholder "__NULL_APP_ID__" for null appIds (instead of the integer 0), so multiple null-appId entries also collide.

Source

Thrown at spring-boot-starters/wx-java-open-multi-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/configuration/services/AbstractWxOpenConfiguration.java:50

  protected WxOpenMultiServices wxOpenMultiServices(WxOpenMultiProperties wxOpenMultiProperties) {
    Map<String, WxOpenSingleProperties> appsMap = wxOpenMultiProperties.getApps();
    if (appsMap == null || appsMap.isEmpty()) {
      log.warn("微信开放平台应用参数未配置,通过 WxOpenMultiServices#getWxOpenService(\"tenantId\")获取实例将返回空");
      return new WxOpenMultiServicesImpl();
    }
    /**
     * 校验 appId 是否唯一,避免使用 redis 缓存 token、ticket 时错乱。
     */
    Collection<WxOpenSingleProperties> apps = appsMap.values();
    if (apps.size() > 1) {
      // 校验 appId 是否唯一
      String nullAppIdPlaceholder = "__NULL_APP_ID__";
      boolean multi = apps.stream()
        // 没有 appId,如果不判断是否为空,这里会报 NPE 异常
        .collect(Collectors.groupingBy(c -> c.getAppId() == null ? nullAppIdPlaceholder : c.getAppId(), Collectors.counting()))
        .entrySet().stream().anyMatch(e -> e.getValue() > 1);
      if (multi) {
        throw new RuntimeException("请确保微信开放平台配置 appId 的唯一性");
      }
    }
    WxOpenMultiServicesImpl services = new WxOpenMultiServicesImpl();

    Set<Map.Entry<String, WxOpenSingleProperties>> entries = appsMap.entrySet();
    for (Map.Entry<String, WxOpenSingleProperties> entry : entries) {
      String tenantId = entry.getKey();
      WxOpenSingleProperties wxOpenSingleProperties = entry.getValue();
      WxOpenInMemoryConfigStorage storage = this.wxOpenConfigStorage(wxOpenMultiProperties);
      this.configApp(storage, wxOpenSingleProperties);
      this.configHttp(storage, wxOpenMultiProperties.getConfigStorage());
      WxOpenService wxOpenService = this.wxOpenService(storage, wxOpenMultiProperties);
      services.addWxOpenService(tenantId, wxOpenService);
    }
    return services;
  }

  /**

View on GitHub (pinned to 1c43293a3c)

Solutions

  1. Ensure each `wx.open.apps.*.appId` (componentAppId) is unique and non-blank.
  2. Restart the application.

Example fix

# before
wx.open.apps:
  a: { appId: wxopen001 }
  b: { appId: wxopen001 }
# after
wx.open.apps:
  a: { appId: wxopen001 }
  b: { appId: wxopen002 }
Defensive patterns

Strategy: validation

Validate before calling

// Spring Boot Open multi: pre-flight component appId uniqueness
Set<String> seen = new HashSet<>();
for (WxOpenSingleProperties p : appsMap.values()) {
    String id = p.getAppId();
    if (id == null || !seen.add(id)) {
        throw new IllegalStateException("Duplicate/null open component appId");
    }
}

Prevention

When it happens

Trigger: Two entries under `wx.open.apps` with the same `appId`, or two entries both with a null appId (both mapped to "__NULL_APP_ID__").

Common situations: Reusing one component appId across tenant blocks; partial config where component appId was left blank on several entries.

Related errors


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