How does spring-boot @ConditionalOnClass work?

前端 未结 1 827
不思量自难忘°
不思量自难忘° 2021-02-04 00:12

How exactly does the @ConditionalOnClass annotation work?

My goal is to load a specific bean only if the jar providing this class is included i

相关标签:
1条回答
  • 2021-02-04 00:54

    Good catch!

    You can use on @Bean method level, but in that case you have to specify your class as a String literal:

    @Bean
    @ConditionalOnClass(name ="de.MyService")
    public MyConditionalBean statistics() {
        return new MyConditionalBean();
    }
    

    I don't remeber already "why", but it is from an existing code of Spring Boot sources.

    0 讨论(0)
提交回复
热议问题