dromara/Sa-Token · error · SaSignException

CODE_12211

CODE_12211

Error message

未找到签名配置,appid={appid}

What it means

Thrown by SaSignMany.getSignTemplate when a non-empty appid is requested but the configured findSaSignConfigMethod returns no SaSignConfig for it (code 12211). The multi-app signature module resolves per-appid sign configuration through a lookup function you register; a null result means that appid has no signing secret/config on this server.

Source

Thrown at sa-token-plugin/sa-token-sign/src/main/java/cn/dev33/satoken/sign/template/SaSignMany.java:55

		return SaSignManager.getSignMany().get(appid);
	};

	/**
	 * 获取 SaSignTemplate,根据 appid
	 * @param appid /
	 * @return /
	 */
	public static SaSignTemplate getSignTemplate(String appid) {

		// appid 为空,返回全局默认 SaSignTemplate
		if(SaFoxUtil.isEmpty(appid)){
			return SaSignManager.getSaSignTemplate();
		}

		// 获取 SaSignConfig
		SaSignConfig config = findSaSignConfigMethod.run(appid);
		if(config == null){
			throw new SaSignException("未找到签名配置,appid=" + appid).setCode(SaSignErrorCode.CODE_12211);
		}

		// 创建 SaSignTemplate 并返回
		return new SaSignTemplate(config);
	}

}

View on GitHub (pinned to ac2c7f6e94)

Solutions

  1. Register configuration for the appid: include it in the map/logic behind SaSignMany.setFindSaSignConfigMethod
  2. Verify the appid string matches exactly (case, whitespace) between the request and the configured keys
  3. Check the backing store (DB table / config file) in the failing environment actually contains the appid entry

Example fix

// before
SaSignMany.setFindSaSignConfigMethod(appid -> map.get(appid));
// after
map.put("app2", new SaSignConfig().setSecretKey("xxx"));
SaSignMany.setFindSaSignConfigMethod(appid -> map.get(appid));
Defensive patterns

Strategy: validation

Validate before calling

if (SaFoxUtil.isNotEmpty(appid) && findSaSignConfigMethod.run(appid) == null) {
  throw new IllegalStateException("no sign config registered for appid: " + appid);
}

Try / catch

try { SaSignMany.getSignTemplate(appid); } catch (SaSignException e) { if (e.getCode() == 12211) return status(401, "unknown appid"); throw e; }

Prevention

When it happens

Trigger: Calling SaSignMany.getSignTemplate("app2") (or a signed request with appid=app2) when the find-sa-sign-config function only knows app1 — appid not added to the config map/repository.

Common situations: New client appid added on the caller but the server-side SaSignMany.setFindSaSignConfigMethod map/DB query was not updated; appid typo or case mismatch (App1 vs app1); config loaded from a table where the row is missing or environment differences between test/prod.

Related errors


AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14). Data as JSON: /api/errors/339e65e7cc7b9ed0. Report an issue: GitHub.