踩坑: springboot项目集成mongodb, 报Consider defining a bean of type com.xxRepository'in your configuration.

踩坑背景:

 项目采用gradle分布式开发,现如今产品需要添加新功能,新功能我这边准备打开一个新的module来进行开发,在原来的基础上开发出一个新的模块,一切依赖都搞定后,代码也写了,就启动准备测试一下,结果发现项目居然报错.启动不起来.

踩坑: springboot项目集成mongodb, 报Consider defining a bean of type com.xxRepository'in your configuration._第1张图片

如上图,直接报错,一看是ActivityRepository这个bean没有被注册到spring,一开始以为自己的包名没有被扫到,于是去检查启动类的扫描范围:

@SpringBootApplication
@ComponentScan(basePackages = {"com.xxxxx.*"})
@EnableTransactionManagement
//@CrossOrigin("http://localhost:4200")
public class ApiApplication {
    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }

    @Bean
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }
}

如上所示,代码扫的是通用包名,所以此时不存在包名出了问题?

网上找了一同都说包名出了问题,一通下来就是没解决问题,最后去看官网,

后来发现是少了一个注解@enableMongoRepositories,加在@ComponentScan下面就可以了 !

你可能感兴趣的:(MongoDB,java后端)