Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
kdxxxx opened this issue Feb 15, 2025 · 1 comment

Comments

@kdxxxx
Copy link

kdxxxx commented Feb 15, 2025

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?

@kdxxxx
Copy link
Author

kdxxxx commented Feb 16, 2025

this is video

2025-02-16.21-09-01-306.mp4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant