Skip to content

Java/Spring: link ConditionalOnProperty annotations to config keys #491

@15290391025

Description

@15290391025

Title

Java/Spring: link @ConditionalOnProperty annotations to config keys and conditional bean methods

Problem

CodeGraph 0.9.6 links @Value and @ConfigurationProperties to config keys, but @ConditionalOnProperty does not appear to emit a comparable config-key reference. This loses an important part of Spring Boot's static wiring: whether a bean exists is often controlled by a config key.

This matters for call graph quality because conditional beans can provide the same bean name or interface under different config values.

Minimal anonymized reproducer

Conditional bean:

@Bean(name = "pricingClient")
@ConditionalOnProperty(prefix = "pricing.client", name = "mode", havingValue = "remote")
public PricingClient remotePricingClient(RemotePricingTransport transport) {
    return new RemotePricingClient(transport);
}

Alternative bean in the same auto-configuration area:

@Bean(name = "pricingClient")
@ConditionalOnProperty(prefix = "pricing.client", name = "mode", havingValue = "local", matchIfMissing = true)
public PricingClient localPricingClient() {
    return new LocalPricingClient();
}

Configuration property:

@ConfigurationProperties(prefix = "pricing.client")
public class PricingClientProperties {
    private String mode = "local";
}

Observed behavior:

codegraph_search("pricing.client.mode")

returns PricingClientProperties-related symbols, but does not surface the @ConditionalOnProperty(prefix="pricing.client", name="mode", ...) bean methods as config-key references.

codegraph_node("remotePricingClient", includeCode=true) includes the annotation in source, but the trail does not expose a config-key reference to pricing.client.mode.

Expected behavior

@ConditionalOnProperty(prefix = "pricing.client", name = "mode", havingValue = "remote") should emit a reference to:

pricing.client.mode

The related method/class should show up when searching or contextualizing that config key.

The relationship should preserve conditional metadata:

  • prefix
  • name / value
  • havingValue
  • matchIfMissing

Why this fits CodeGraph's positioning

CodeGraph is not expected to fully simulate Spring runtime conditions, but @ConditionalOnProperty is a static annotation with a statically recoverable config key. Linking it improves local graph accuracy without needing runtime access, and it helps agents explain why a bean implementation may or may not exist.

Suggested implementation shape

  • Extend Spring annotation extraction to handle @ConditionalOnProperty.
  • Build dotted keys from:
    • prefix
    • name
    • value
  • Support array values:
@ConditionalOnProperty(prefix = "x", name = {"a", "b"})
  • Emit references from the annotated class or method to config-key constant nodes.
  • Include condition metadata in edge details if the graph schema supports it.

Acceptance criteria

  • Given:
@Bean
@ConditionalOnProperty(prefix = "pricing.client", name = "mode", havingValue = "remote")
PricingClient pricingClient() { ... }

codegraph_search("pricing.client.mode") should include the conditional bean method.

  • codegraph_node("pricingClient", includeCode=true) should show a reference/trail entry to the config key pricing.client.mode.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions