Hello, i have created a simple autoconfiguration starter using the new way of declaring autoconfiguration class (in the file called org.springframework.boot.autoconfigure.AutoConfiguration.imports)

here are the two classes in my starter :

public interface MyClient {

  void method();

}
@AutoConfiguration
@ConditionalOnBean(MyClient.class)
public class MyAutoConfiguration {

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

}

so basically just providing a string bean if a bean of type MyClient is in the app context. And the content of the AutoConfiguration.imports file is : com.example.autoconfiguration.MyAutoConfiguration

Then i have my application using this starter, containing the following classes :

@SpringBootApplication
@EnableFeignClients
public class DemoApplication {

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

}
@FeignClient(name = "myFeign")
public interface MyFeignClient extends MyClient {

  @RequestMapping(method = RequestMethod.POST, path = "/hello")
  void method();
}
@Service
public class MyService {
  private final String hello;

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

the application fails to start saying that there is no bean of type String to inject in MyService...

If in my starter i use spring.factories instead, everything works fine. I am using spring boot 3.0.1 and spring cloud 2022.0.0.

i am attaching the two projects, you just have to publish the autoconfiguration to your local maven repo using ./gradlew publishToMavenLocal in the project, before starting the app.

application.zip

my-autoconfiguration.zip

Comment From: scottfrederick

Thanks for getting in touch. The problem in the provided sample has nothing to do with how auto-configurations are imported. In your library project you have this:

@AutoConfiguration
@ConditionalOnBean(MyClient.class)
public class MyAutoConfiguration {
    ...
}

This auto-configuration will not run in your sample because nothing is creating a bean of type MyClient.class to satisfy the @ConditionalOnBean. If you run the application with the -Ddebug system property to create an auto-configuration conditions report, you will see this in the output:

Negative matches:
-----------------

    ...

   MyAutoConfiguration:
      Did not match:
         - @ConditionalOnBean (types: com.example.autoconfiguration.MyClient; SearchStrategy: all) did not find any beans of type com.example.autoconfiguration.MyClient (OnBeanCondition)

Did you mean to use @ConditionalOnClass instead of @ConditionalOnBean?

If in my starter i use spring.factories instead, everything works fine.

This seems unlikely to me, given how you're using the @ConditionalOnBean. Can you modify your samples to show this?

Comment From: philwebb

I also took a look at this one and I don't think it's related to the auto-configuration imports file.

I tried changing MyFeignClient from a @Component to a @FeignClient("my"). This allows it to be discovered by @MyFeignClient and registered as a bean. Unfortunately it still doesn't solve your issue because FeignClientsRegistrar registers a FeignClientFactoryBean which isn't being picked up by @ConditionalOnBean.

I've opened https://github.com/spring-projects/spring-framework/issues/29799 to get some clarification from the Framework team to see if we need to open an issue with spring-cloud-openfeign.