简体   繁体   中英

IntelliJ and Spring boot test: unresolved bean, could not autowire

I have got a gradle imported project in IntelliJ, kotlin. Compilations go fine, tests are run fine both via command line and via IntelliJ. The only thing I'd like gone is the red error highlighting saying eg "Could not autowire. No beans of 'FooRepository' type found". The weird part is that I've got exact same setup in another PC and there it works fine. Using IntelliJ 2021.1 on Ubuntu. I can't recall this in the previous versions.

在此处输入图像描述

The FooRepository is declared with @Repository annotation, like this:

@Repository
class FooTypeRepository(
    @Autowired var jdbcTemplate: NamedParameterJdbcTemplate
){...}

I had same issue, resolved it by deleting .idea folder and reimporting the project. Sometimes IntelliJ just need to reimport and reindex everything.

Your class FooRepository needs to be a Spring Bean. It has to have some annotation indicating that it's a bean. For example annotation @Repository or just @Component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM