alibaba/spring-cloud-alibaba · error · IllegalStateException
spring.nacos.config.proxy.druid.data-id is required
Error message
spring.nacos.config.proxy.druid.data-id is required
What it means
Thrown by the NacosDruidFilterConfiguration @Bean method during Spring context startup. The bean is only created when 'spring.nacos.config.proxy.druid.enabled' is set to 'true' AND a NacosConfigManager bean exists. The method then reads 'spring.nacos.config.proxy.druid.data-id' from the Environment; if that property is absent (getProperty returns null), the bean cannot be constructed and startup aborts with IllegalStateException. The proxy feature routes Druid SQL monitoring configuration through Nacos, so it needs to know which Nacos dataId holds the Druid config.
Source
Thrown at spring-cloud-alibaba-starters/spring-alibaba-nacos-config/src/main/java/com/alibaba/cloud/nacos/proxy/druid/NacosDruidFilterConfiguration.java:36
import com.alibaba.cloud.nacos.NacosConfigManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
@Configuration
public class NacosDruidFilterConfiguration {
@Bean
@ConditionalOnProperty(value = "spring.nacos.config.proxy.druid.enabled", havingValue = "true")
@ConditionalOnBean(NacosConfigManager.class)
public NacosDruidConfigFilter nacosDruidFilter(Environment environment) {
String proxyDataId = environment.getProperty("spring.nacos.config.proxy.druid.data-id");
if (proxyDataId == null) {
throw new IllegalStateException("spring.nacos.config.proxy.druid.data-id is required");
}
return new NacosDruidConfigFilter(proxyDataId);
}
}
View on GitHub (pinned to 115d590110)
Solutions
- Add spring.nacos.config.proxy.druid.data-id=<your-druid-config-data-id> to application.yml, ensuring the dataId exists in your Nacos config server.
- If you did not intend to use the Druid proxy, remove or set spring.nacos.config.proxy.druid.enabled=false (or omit it entirely — the default is disabled).
- Verify the property key is spelled exactly 'spring.nacos.config.proxy.druid.data-id' — Spring relaxed binding accepts camelCase or underscores, but typos in the stem will not match.
Example fix
# before (broken)
spring:
nacos:
config:
proxy:
druid:
enabled: true
# after (fixed)
spring:
nacos:
config:
proxy:
druid:
enabled: true
data-id: druid-sql-config.yaml Defensive patterns
Strategy: validation
Validate before calling
// Before enabling the druid proxy, verify the data-id property exists
@Value("${spring.nacos.config.proxy.druid.enabled:false}")
boolean druidEnabled;
@Value("${spring.nacos.config.proxy.druid.data-id:}")
String druidDataId;
// In a @PostConstruct or configuration check:
if (druidEnabled && !StringUtils.hasText(druidDataId)) {
throw new IllegalStateException(
"spring.nacos.config.proxy.druid.data-id must be set when druid proxy is enabled");
} Prevention
- Always set data-id in the same YAML block where you set enabled=true to avoid partial configuration.
- Use a custom @ConfigurationProperties validation bean that checks related properties together.
- Add a startup health check that asserts the druid dataId exists in Nacos before the bean is created.
When it happens
Trigger: Setting spring.nacos.config.proxy.druid.enabled=true in application.yml/properties without also setting spring.nacos.config.proxy.druid.data-id. The NacosConfigManager bean must also be present (it is auto-configured when spring-cloud-starter-alibaba-nacos-config is on the classpath and Nacos config server-addr is configured). The @ConditionalOnProperty match means the @Bean method is invoked, and the null check at line 35 fires.
Common situations: 1) A developer copies a partial config snippet that enables the druid proxy but forgets the data-id. 2) Environment-specific overrides (dev vs prod profile) set enabled=true but the profile-specific data-id is missing. 3) The data-id key is misspelled or uses wrong hyphen/camelCase convention so Spring does not bind it.
Related errors
- ConfigService not available
- NacosConfigManager not available
- NacosConfigProperties not available
- ConfigService is not initialized
- Binder not available in BootstrapContext
AI-assisted analysis of alibaba/spring-cloud-alibaba@115d590110 (2026-08-14).
Data as JSON: /api/errors/888eaedae0d8c56f.
Report an issue: GitHub.