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:
- Package scanning scope: Spring Boot only scans packages below the package containing your
@SpringBootApplicationclass. 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 hereNote: You typically do not need to add @Repository to Spring Data interfaces; Spring Boot auto-detects them.
-
Missing Spring Boot starter dependency: Ensure your
pom.xmlorbuild.gradleincludes the correct starter, such asspring-boot-starter-data-jpa. Without it, Spring does not auto-configure repository beans. -
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.
-
Multiple application contexts: If you are using custom
@Configurationclasses 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.