Search code examples
spring-bootintellij-ideaspring-boot-starter

IntelliJ Could not autowire. No beans of 'xxx' type found. Custom Starter Library


We created a Spring starter library where we expose a configuration class. Below is the spring.factories and the configuration class

spring.factories

org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.sample.SampleRequestFilter

SampleRequestFilter.class

@Configuration
@AutoConfigureOrder(Integer.MIN_VALUE)
@ConditionalOnProperty({"sample.property"})
public class SampleRequestFilter {
    @Bean
    @ConditionalOnMissingBean
    public ExchangeFilterFunction sampleFilter(Blabla blabla) {
        return (clientRequest, nextFilter) -> {
            .... bla bla
            return nextFilter.exchange(clientRequest);
        };
    }
}

In my project attempting to use this starter library I have added the starter library as as a dependency implementation 'blablabla'. Everything works fine and my bean is generated as expected. However, IntelliJ complains about the SampleRequestFilter saying Could not autowire. No beans of 'ExchangeFilterFunction' type found. despite the fact that the application starts and correctly autowires a bean.

Did I miss anything in my understanding of how to create starter libraries? Or is this just an IntelliJ bug? If the latter is there anyway to suppress this without adding annotations to my code? I have upgraded to the latest version of IntelliJ and have tried invalidating caches.


Solution

  • Well, I finally figured it out. If you too are facing this issue then add the following dependencies to your project:

        annotationProcessor 'org.springframework.boot:spring-boot-autoconfigure-processor'
    

    I assume IntelliJ just scans the generated metadata to look for beans.