W3docs

intellij incorrectly saying no beans of type found for autowired repository

If IntelliJ is saying "No beans of type 'X' found for autowiring" for a repository that you are trying to autowire, it means that the Spring application context does not contain a bean of the specified type.

If IntelliJ is saying "No beans of type 'X' found for autowiring" for a repository that you are trying to autowire, it usually means the IDE's static analysis cannot resolve the bean, or the Spring application context does not contain it at runtime. This is often just an IDE warning and does not prevent your application from running. This can happen for a few reasons:

  1. Package scanning scope: Spring Boot only scans packages below the package containing your @SpringBootApplication class. Ensure your repository interface is in the same package or a sub-package.
// Correct package structure
com.example.app          // @SpringBootApplication here
├── controller
├── service
└── repository           // Repository interfaces here

Note: You typically do not need to add @Repository to Spring Data interfaces; Spring Boot auto-detects them.

  1. Missing Spring Boot starter dependency: Ensure your pom.xml or build.gradle includes the correct starter, such as spring-boot-starter-data-jpa. Without it, Spring does not auto-configure repository beans.

  2. Typo or incorrect import: Verify that the repository interface name matches exactly and that the correct package is imported in the class where it is autowired.

  3. Multiple application contexts: If you are using custom @Configuration classes or component scanning filters, ensure the repository is included in the same context as the class autowiring it.

If the application runs without errors, you can safely ignore the IntelliJ warning. To suppress it, you can add @SuppressWarnings("SpringJavaInjectionPointsAutowiringInspection") or configure IntelliJ's inspection settings. Otherwise, check your application logs for actual startup failures.