Describe the bug Hello, i would like to use @ConditionalOnBean(MyFeignClient.class) but this seems to be always evaluated to false. I am using spring boot 3.0.1 with spring cloud 2022.0.0

@SpringBootApplication
@EnableFeignClients
public class DemoApplication {

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

}
@FeignClient(name = "myFeign")
public interface MyClient {
}
@Configuration
@ConditionalOnBean(MyClient.class)
public class MyConfig {

  @Bean("hello")
  public String hello() {
    return "hello";
  }

}
@Service
public class MyService {

  private final String hello;

  public MyService(String hello) {
    this.hello = hello;
  }
}

On service startup i end up with :

***************************
APPLICATION FAILED TO START
***************************

Description:

Parameter 0 of constructor in com.example.demo.child.MyService required a bean of type 'java.lang.String' that could not be found.

if i remove @ConditionalOnBean(MyClient.class) the application runs fine

Please find the test app attached

demo.zip

Comment From: OlgaMaciaszek

This is due to the order in which beans are being created in the Spring Context. Your bean is instantiated from a user-provided configuration while the Feign clients bean are created using a factory bean in a phase that happens later, so you cannot use them in a condition in this way. Please note that Spring Boot docs indicate that:

You need to be very careful about the order in which bean definitions are added, as these conditions are evaluated based on what has been processed so far. For this reason, we recommend using only @ConditionalOnBean and @ConditionalOnMissingBean annotations on auto-configuration classes (since these are guaranteed to load after any user-defined bean definitions have been added).