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-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?