alibaba/spring-cloud-alibaba · error · IllegalArgumentException

ConsulDataSource server-host is empty

Error message

ConsulDataSource server-host is empty

What it means

Thrown by ConsulDataSourceProperties.preCheck during Sentinel datasource initialization. The ConsulDataSourceProperties.host field is @Nullable with no default value — it must be explicitly set. preCheck is called by the Sentinel datasource auto-configuration before creating the FactoryBean, ensuring required properties are present before attempting a connection.

Source

Thrown at spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ConsulDataSourceProperties.java:65

	 * consul acl-token.
	 */

	private @Nullable String token;

	/**
	 * data key in Redis.
	 */
	private @Nullable String ruleKey;

	/**
	 * Request of query will hang until timeout (in second) or get updated value.
	 */
	private int waitTimeoutInSecond = 1;

	@Override
	public void preCheck(String dataSourceName) {
		if (StringUtils.isEmpty(host)) {
			throw new IllegalArgumentException("ConsulDataSource server-host is empty");
		}
		if (StringUtils.isEmpty(ruleKey)) {
			throw new IllegalArgumentException(
					"ConsulDataSource ruleKey can not be empty");
		}
	}

	public @Nullable String getHost() {
		return host;
	}

	public void setHost(@Nullable String host) {
		this.host = host;
	}

	public int getPort() {
		return port;
	}

View on GitHub (pinned to 115d590110)

Solutions

  1. Add spring.cloud.sentinel.datasource.<name>.consul.host=<consul-server-address> to your configuration.
  2. Verify the property key matches the expected prefix: spring.cloud.sentinel.datasource.<datasource-name>.consul.host.
  3. If using environment variables, ensure the mapped variable (e.g., SPRING_CLOUD_SENTINEL_DATASOURCE_DS1_CONSUL_HOST) is exported.

Example fix

# before (broken — host missing)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          consul:
            ruleKey: sentinel-flow-rules

# after (fixed)
spring:
  cloud:
    sentinel:
      datasource:
        ds1:
          consul:
            host: consul.local
            ruleKey: sentinel-flow-rules
Defensive patterns

Strategy: validation

Validate before calling

// In application.yml validation or a @ConfigurationProperties validator
@ConfigurationProperties(prefix = "spring.cloud.sentinel.datasource")
public class SentinelDataSourceCheck {
    // Validate consul host before NacosContextRefresher initializes
}

// Or simply: ensure the property is set in config
// spring.cloud.sentinel.datasource.<name>.consul.host must be non-empty

Prevention

When it happens

Trigger: Configuring a Sentinel datasource of type 'consul' (spring.cloud.sentinel.datasource.<name>.consul.host not set). The host field defaults to null, so if it is not provided in configuration, StringUtils.isEmpty(host) is true and IllegalArgumentException fires during bean initialization.

Common situations: 1) Developer configures spring.cloud.sentinel.datasource.ds1.consul.ruleKey but forgets consul.host. 2) Profile-specific configuration omits the host property. 3) Consul host was expected from an environment variable that is not set.

Related errors


AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14). Data as JSON: /api/errors/a277a1940ea7a8be. Report an issue: GitHub.