Skip to content

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

@kdxxxx

Description

@kdxxxx

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

this is my code
springboot version is 3.3.4,cloud 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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    for: stackoverflowA question that's better suited to stackoverflow.comstatus: declinedA suggestion or change that we don't feel we should currently apply

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions