dromara/Sa-Token · error · SaTokenException
CODE_30301
CODE_30301
Error message
请配置:jwtSecretKey
What it means
Thrown by SaTempTemplateForJwt.getJwtSecretKey when the global config has no jwt-secret-key value. Every JWT operation (create/parse) needs the secret for signing and verification, so the plugin fails fast rather than defaulting to an insecure key.
Source
Thrown at sa-token-plugin/sa-token-temp-jwt/src/main/java/cn/dev33/satoken/temp/jwt/SaTempTemplateForJwt.java:84
/**
* 获取指定 value 的 temp-token 列表记录
* @param value /
* @return /
*/
public List<String> getTempTokenList(Object value) {
throw new ApiDisabledException("jwt cannot get token list").setCode(SaTempJwtErrorCode.CODE_30304);
}
/**
* 获取jwt秘钥
* @return jwt秘钥
*/
@Override
public String getJwtSecretKey() {
String jwtSecretKey = SaManager.getConfig().getJwtSecretKey();
if(SaFoxUtil.isEmpty(jwtSecretKey)) {
throw new SaTokenException("请配置:jwtSecretKey").setCode(SaTempJwtErrorCode.CODE_30301);
}
return jwtSecretKey;
}
}
View on GitHub (pinned to ac2c7f6e94)
Solutions
- Set the secret in configuration: sa-token.jwt-secret-key: your-strong-secret (min length per jjwt, typically >= 32 chars for HS256)
- Verify the property is actually loaded (actuator /env or a breakpoint on SaManager.getConfig().getJwtSecretKey())
- In multi-module projects, ensure the yml defining the key is on the active module's classpath
Example fix
# before sa-token: token-name: satoken # after sa-token: token-name: satoken jwt-secret-key: "PleaseChangeMe_0123456789ABCDEF"
Defensive patterns
Strategy: validation
Validate before calling
if(SaFoxUtil.isEmpty(SaManager.getConfig().getJwtSecretKey())) {
// fail startup with a clear message before any JWT call
} Prevention
- Add a startup assertion for jwt-secret-key when the jwt plugin is on the classpath
- Load secrets from env/vault, not committed yml
When it happens
Trigger: Using SaTempUtil/any JWT temp-token API with sa-token.jwt-secret-key absent in application.yml; the config key is misspelled or the yml profile that defines it is not active.
Common situations: Adding the sa-token-temp-jwt (or sa-token-jwt) dependency without adding the config; config living in a different Spring profile; whitespace/indentation errors in yml under sa-token.
Related errors
AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14).
Data as JSON: /api/errors/462436145903b488.
Report an issue: GitHub.