dromara/Sa-Token · critical · SaTokenException
解析 sa-token.alone-redisson 配置失败
Error message
解析 sa-token.alone-redisson 配置失败
What it means
SaTokenException (wrapping the original as cause) thrown by SaAloneRedissonRegister.buildConfig when Config.fromYAML fails for either the inline config string or the file — i.e. malformed yaml, invalid Redisson option names/values, or IO errors while reading the file. It is the generic catch-all after the specific 'not configured' (116) and 'file not found' (118) cases have been separated out.
Source
Thrown at sa-token-plugin/sa-token-alone-redisson/src/main/java/cn/dev33/satoken/dao/alone/SaAloneRedissonRegister.java:89
* 解析 Redisson 原生 yaml:优先 config,其次 file
*/
public static Config buildConfig(SaAloneRedissonProperties properties) {
try {
Config config;
if (StringUtils.hasText(properties.getConfig())) {
config = Config.fromYAML(properties.getConfig());
} else if (StringUtils.hasText(properties.getFile())) {
try (InputStream in = openFile(properties.getFile())) {
config = Config.fromYAML(in);
}
} else {
throw new SaTokenException("请配置 sa-token.alone-redisson.config 或 sa-token.alone-redisson.file");
}
return config;
} catch (SaTokenException e) {
throw e;
} catch (Exception e) {
throw new SaTokenException("解析 sa-token.alone-redisson 配置失败", e);
}
}
private static InputStream openFile(String file) throws Exception {
String path = file.trim();
Resource resource;
if (path.startsWith("classpath:")) {
resource = new ClassPathResource(path.substring("classpath:".length()));
} else if (path.startsWith("file:")) {
resource = new FileSystemResource(path.substring("file:".length()));
} else {
resource = new ClassPathResource(path);
}
if (!resource.exists()) {
throw new SaTokenException("未找到 Redisson 配置文件: " + file);
}
return resource.getInputStream();
}View on GitHub (pinned to ac2c7f6e94)
Solutions
- Inspect e.getCause() — it carries the underlying Redisson/IO exception with the exact yaml line.
- Validate the yaml separately (e.g. redisson's Config.fromYAML in a scratch test) against the exact Redisson version the plugin ships.
- Replace tabs with spaces and fix indentation; ensure option names match Redisson's schema (singleServerConfig, clusterServersConfig, ...).
- If reading from file:, confirm the file parses as yaml, not JSON (Redisson supports json via fromJSON instead).
Example fix
# before (invalid: tab indentation)
sa-token:
alone-redisson:
config: |
singleServerConfig:
\taddress: redis://127.0.0.1:6381
# after
sa-token:
alone-redisson:
config: |
singleServerConfig:
address: "redis://127.0.0.1:6381"
database: 1 Defensive patterns
Strategy: try-catch
Validate before calling
// in a unit test, parse the same yaml the app will use
Config.fromYAML(new ClassPathResource("alone-redisson.yaml").getInputStream()); // fails here, not at boot Try / catch
try { SaAloneRedissonRegister.buildConfig(props); } catch (SaTokenException e) { Throwable c = e.getCause(); // c holds the yaml/Redisson parse error with line info; fix config accordingly } Prevention
- Keep the Redisson yaml version-locked to the Redisson version the plugin ships; re-validate after dependency upgrades.
- Use spaces-only indentation and validate the file in CI with a parse test.
When it happens
Trigger: sa-token.alone-redisson.config containing invalid yaml (tabs, bad indentation, unterminated quotes) or Redisson options that don't exist for the bundled Redisson version; file: pointing to a yaml with e.g. clusterConfig missing required fields; encoding issues in the file.
Common situations: Copying a Redisson yaml from a different Redisson major version (options renamed between 2.x/3.x); using tabs instead of spaces; a file whose content is actually JSON.
Related errors
AI-assisted analysis of dromara/Sa-Token@ac2c7f6e94 (2026-08-14).
Data as JSON: /api/errors/f87bb7cfc47a699e.
Report an issue: GitHub.