1

I created a basic Repository for my model "BoardingPass".

@Repository
public interface BoardingPassRepository extends MongoRepository<BoardingPass, String> {

}

When trying to use the Repository, IntelliJ underlines the repository red and displays me "Could not autowire. No Beans of "BoardingPassRepository" found.". I fixed this problem by using @EnableMongoRepository, so now the Application runs, yet IntelliJ still displays this error. How do I correctly fix this problem so that not only the program runs, but also IntelliJ accepts it?

@SpringBootApplication
@EnableMongoRepositories(basePackageClasses = BoardingPassRepository.class)
public class Main implements CommandLineRunner {
@Autowired
private BoardingPassRepository repository;
    public static void main(String[] args) {
        SpringApplication.run(Main.class, args);

    }


    @Override
    public void run(String... args) throws Exception {

    }
}
  • what is the package of your Main class and BoardingPassRespository interface? – Ismail Jun 21 '22 at 12:30
  • 1
    I guess, your repository class is not getting scan for creating bean in IOC. either repository class package should be same as main class package or repository class package should be a sub-package of main class package. – Abhale Amol Jun 21 '22 at 12:43
  • Sometimes Intellij just gets confused. Try going through some of the steps here: https://stackoverflow.com/questions/5905896/intellij-inspection-gives-cannot-resolve-symbol-but-still-compiles-code – Stomf Jun 21 '22 at 15:13
  • Thanks for your help, it was indeed a problem with the ComponentScanning which I solved using @ComponentScan(basePackages = { "Server.repository" }) – sebastian307 Jun 22 '22 at 20:25

0 Answers0