Skip to content

Log4j2EventListener's @ConditionalOnProperty has no effect - the listener always runs #4244

Description

@ramanathan1504

Description

Log4j2EventListener carries @ConditionalOnProperty("spring.cloud.config.watch.enabled") but always runs.

It is registered twice:

  • as @Component — the condition applies
  • in META-INF/spring.factories (line 17) as an ApplicationListener — the condition cannot apply, because SpringApplication instantiates these directly, with no bean definition to suppress

So spring.cloud.config.watch.enabled=false disables nothing.

Version: 2.x 04c93c1d33 · JDK 21 · Spring Boot 3.4.3

Logs

Property set to false, monitorInterval 300s:

RELOADED - the refresh event drove the reload, 298 seconds before
           the monitorInterval would have

298s ahead of the interval, so the event drove it, not the timer.

Reproduction

Run with -Dspring.cloud.config.watch.enabled=false and publish an EnvironmentChangeEvent (POST /actuator/refresh). Log4j reconfigures anyway.

Suggested fix

Check the property inside onApplicationEvent against the Environment — smallest change, keeps the documented switch meaningful. Or drop @ConditionalOnProperty so the source stops promising a switch that does not exist.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Status
    To triage

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions