spring-cloud / spring-cloud/spring-cloud-config

the @RefreshScope on bean make annonation @ConditionOnMissingBean inaffective but some annonation like @ConditionOnProperty works well

Open
#2,750 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

waiting-for-triage
Dominant language
Java
Stars
2k
Forks
1.3k
Avg merge
2d 59m
Merged PRs (30d)
16

Description

When I add @RefreshScope on a bean (such as bean ‘myBean’) as well as @ConditionOnMissingBean(A.class), though A.class and bean a is in spring container, the bean 'myBean' always loaded in spring ,the @ConditionOnMissingBean likes unaviable . But I remove @RefreshScope, it works normal and the bean 'myBean' is not loader in spring.

this is my code
springboot version is 3.3.4,cloud-config version is 4.1.2

`

@SpringBootApplication
public class ReactiveApplication {

public static void main(String[] args) {
    SpringApplication.run(ReactiveApplication.class);
}

@ConditionalOnMissingBean(ReactiveApplication.class)
@RefreshScope
@Component
public static  class TestConfig {
    static {
        System.out.println("TestConfig class loaded");
    }
}

}

`
ReactiveApplication is main springboot class, so it is always loaded in spring, so normally @ConditionalOnMissingBean is uneffective and TestConfig is not loaded. But actually TestConfig was loaded and print “TestConfig class loaded”. However, When remove "@RefreshScope", it was normal and not print "TestConfig class loaded".

I just think the all anonation like @Conditionxxx is unavaiable with RefreshScope, but when I use @ConditonOnProperty and @ConditionalOnMissingClass, it works normally. Why?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the supplied ReactiveApplication example with Spring Boot 3.3.4 and Spring Cloud Config 4.1.2, comparing bean registration with and without @RefreshScope. Start by tracing how @RefreshScope and @ConditionalOnMissingBean process TestConfig and ReactiveApplication; done means explaining the differing behavior and identifying a focused regression test or fix.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, spring-boot
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.