报错信息如下:
APPLICATION FAILED TO START
Description:
Parameter 0 of constructor in com.service.TrackRecordService required a bean of type ‘com.mongo.TrackRecordRepo’ that could not be found.
Action:
Consider defining a bean of type ‘com.mongo.TrackRecordRepo’ in your configuration.
Process finished with exit code 1
TrackRecordRepo是一个接口继承了MongoRepository,同时也使用了@Repository进行注入,编码阶段无报错,但运行起来就报以上报错,显示spring扫描不到,找不到相关的bean。
解决办法:
在@SpringBootApplication主类加上@EnableMongoRepositories注解,让spring扫描mongo相关的类
@SpringBootApplication
@EnableMongoRepositories(basePackages = ["com.mongo"])