alibaba/spring-cloud-alibaba · error · IllegalArgumentException
ZookeeperDataSource server-addr is empty
Error message
ZookeeperDataSource server-addr is empty
What it means
Thrown by ZookeeperDataSourceProperties.preCheck when serverAddr is empty. Unlike other datasource properties, serverAddr has a default value ('localhost:2181'), so this error only fires when the property is explicitly set to empty OR cleared and the environment fallback also yields empty. The check first tries the env property 'spring.cloud.sentinel.datasource.zk.server-addr' as a fallback before throwing.
Source
Thrown at spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ZookeeperDataSourceProperties.java:54
}
private String serverAddr = "localhost:2181";
private @Nullable String path;
private @Nullable String groupId;
private @Nullable String dataId;
@Override
public void preCheck(String dataSourceName) {
if (StringUtils.isEmpty(serverAddr)) {
Environment env = this.getEnv();
if (env != null) {
serverAddr = env.getProperty("spring.cloud.sentinel.datasource.zk.server-addr", "");
}
if (StringUtils.isEmpty(serverAddr)) {
throw new IllegalArgumentException(
"ZookeeperDataSource server-addr is empty");
}
}
}
public String getServerAddr() {
return serverAddr;
}
public void setServerAddr(String serverAddr) {
this.serverAddr = serverAddr;
}
public @Nullable String getPath() {
return path;
}
public void setPath(@Nullable String path) {View on GitHub (pinned to 115d590110)
Solutions
- Set spring.cloud.sentinel.datasource.<name>.zk.server-addr=<zk-host:port> to a valid Zookeeper address, or set the global fallback spring.cloud.sentinel.datasource.zk.server-addr.
- Remove any explicit empty-string override that clears the 'localhost:2181' default.
- If using a placeholder (${ZK_ADDR}), ensure the environment variable is set to a non-empty value.
Example fix
# before (broken — server-addr explicitly empty)
spring:
cloud:
sentinel:
datasource:
ds1:
zk:
server-addr: ""
path: /sentinel/rules
# after (fixed)
spring:
cloud:
sentinel:
datasource:
ds1:
zk:
server-addr: zk.local:2181
path: /sentinel/rules Defensive patterns
Strategy: validation
Validate before calling
// Ensure serverAddr is set for zk Sentinel datasource
// Note: defaults to 'localhost:2181' but can be explicitly cleared
String serverAddr = props.getZk().getServerAddr();
if (!StringUtils.hasText(serverAddr)) {
// Try the global fallback
serverAddr = env.getProperty("spring.cloud.sentinel.datasource.zk.server-addr", "localhost:2181");
props.getZk().setServerAddr(serverAddr);
} Prevention
- Do not explicitly set server-addr to an empty string — the default 'localhost:2181' is usually preferable.
- Use the global fallback property spring.cloud.sentinel.datasource.zk.server-addr for shared ZK addresses across multiple datasources.
- Validate ZK connectivity in a startup health check.
When it happens
Trigger: Configuring a Sentinel datasource of type 'zk' with serverAddr explicitly set to empty string, or the default was overridden to empty AND spring.cloud.sentinel.datasource.zk.server-addr is also unset or empty. Since the field defaults to 'localhost:2181', this requires actively clearing it.
Common situations: 1) Developer sets spring.cloud.sentinel.datasource.<name>.zk.server-addr to an empty string or a placeholder that resolves to empty. 2) A profile override clears the default by setting server-addr to blank. 3) Programmatic configuration that sets serverAddr to null or empty after construction.
Related errors
- serverAddr, groupId, and dataId must not be null
- serverAddr and path must not be null
- ConsulDataSource server-host is empty
- ConsulDataSource ruleKey can not be empty
- [Sentinel Starter] DataSource {} file cannot be null
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/446956827e43ea18.
Report an issue: GitHub.