{"record":{"id":"a277a1940ea7a8be","repo":"alibaba/spring-cloud-alibaba","slug":"consuldatasource-server-host-is-empty","errorCode":null,"errorMessage":"ConsulDataSource server-host is empty","messagePattern":"ConsulDataSource server-host is empty","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ConsulDataSourceProperties.java","lineNumber":65,"sourceCode":"\t * consul acl-token.\n\t */\n\n\tprivate @Nullable String token;\n\n\t/**\n\t * data key in Redis.\n\t */\n\tprivate @Nullable String ruleKey;\n\n\t/**\n\t * Request of query will hang until timeout (in second) or get updated value.\n\t */\n\tprivate int waitTimeoutInSecond = 1;\n\n\t@Override\n\tpublic void preCheck(String dataSourceName) {\n\t\tif (StringUtils.isEmpty(host)) {\n\t\t\tthrow new IllegalArgumentException(\"ConsulDataSource server-host is empty\");\n\t\t}\n\t\tif (StringUtils.isEmpty(ruleKey)) {\n\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\"ConsulDataSource ruleKey can not be empty\");\n\t\t}\n\t}\n\n\tpublic @Nullable String getHost() {\n\t\treturn host;\n\t}\n\n\tpublic void setHost(@Nullable String host) {\n\t\tthis.host = host;\n\t}\n\n\tpublic int getPort() {\n\t\treturn port;\n\t}","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/alibaba/spring-cloud-alibaba/blob/115d5901102009492e05d5ec18c3f79cad4077d0/spring-cloud-alibaba-starters/spring-cloud-alibaba-sentinel-datasource/src/main/java/com/alibaba/cloud/sentinel/datasource/config/ConsulDataSourceProperties.java#L47-L83","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add spring.cloud.sentinel.datasource.<name>.consul.host=<consul-server-address> to your configuration.","Verify the property key matches the expected prefix: spring.cloud.sentinel.datasource.<datasource-name>.consul.host.","If using environment variables, ensure the mapped variable (e.g., SPRING_CLOUD_SENTINEL_DATASOURCE_DS1_CONSUL_HOST) is exported."],"exampleFix":"# before (broken — host missing)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          consul:\n            ruleKey: sentinel-flow-rules\n\n# after (fixed)\nspring:\n  cloud:\n    sentinel:\n      datasource:\n        ds1:\n          consul:\n            host: consul.local\n            ruleKey: sentinel-flow-rules","handlingStrategy":"validation","validationCode":"// In application.yml validation or a @ConfigurationProperties validator\n@ConfigurationProperties(prefix = \"spring.cloud.sentinel.datasource\")\npublic class SentinelDataSourceCheck {\n    // Validate consul host before NacosContextRefresher initializes\n}\n\n// Or simply: ensure the property is set in config\n// spring.cloud.sentinel.datasource.<name>.consul.host must be non-empty","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When configuring a consul Sentinel datasource, always set host, ruleKey, and port together.","Use a config template or snippet that includes all required consul properties.","Add a startup assertion that validates all Sentinel datasource configs before the datasource beans are created."],"tags":["sentinel","consul","datasource","configuration","validation"],"backgroundTag":null,"analyzedSha":"115d5901102009492e05d5ec18c3f79cad4077d0","analyzedAt":"2026-08-14T04:47:13.900Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}