False "Could not autowire" error in IDEA 2019.2 (and IIRC 2019.1 and earlier versions too)


I have reported this in YouTrack too, but thought there might be a workaround available so I am posting here too.

I uploaded a sample project (resolution-error.zip) to https://uploads.services.jetbrains.com/ but I am not sure if it got uploaded successfully as it shows these success/error message combo:

Error #-200: HTTP Error.
Upload complete!

Anyway, I have defined a meta annotation like this in a common module:

package org.behrang.bugreport;

import org.springframework.boot.autoconfigure.SpringBootApplication;

* Marker package for component scan.
* @see SpringBootApplication#scanBasePackageClasses()
public interface BugReportPackage {
package org.behrang.bugreport.api.common.annotations;

import org.behrang.bugreport.BugReportPackage;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.lang.annotation.Documented;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@SpringBootApplication(scanBasePackageClasses = BugReportPackage.class)
public @interface BugReportApplication {

In a module named foo that depends on this common module, I have defined an application entry point:

package org.behrang.bugreport.foo;

import org.behrang.bugreport.api.common.annotations.BugReportApplication;
import org.springframework.boot.SpringApplication;

public class Application {

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

There's also a service defined in this module:

package org.behrang.bugreport.foo.service;

import org.springframework.stereotype.Service;

public class FooService {

public void foo() {


And this test:

package org.behrang.bugreport.foo.service;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;

import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;

@SpringBootTest(webEnvironment = RANDOM_PORT)
public class FooServiceSmokeTest {

private FooService fooService;

public void shouldAutowireFooService() {

The test passes successfully both from CLI and from within IDEA, but IDEA marks:

private FooService fooService;

with an error:

I think this happens because:

1. The BugReportApplication meta annotation and BugReportPackage marker interface are defined in the common module

2. The application uses the BugReportApplication meta annotation instead of SpringBootApplication

Right now I have disabled the inspection to suppress the error, but are there any workarounds to make IDEA to properly parse this project and understand that there actually is a bean that can be autowired?

1 comment
Comment actions Permalink


The issue is being reviewed in the scope of the following YouTrack item: 



Please sign in to leave a comment.