问题描述
以下是我的目录结构
- com.example
- com.example.common
- com.example.test
- com.example.test.repository
我的主要春季靴子课程如下
package com.example.test;
@Import({ AutoConfig.class })
@SpringBootApplication
public class testApplication {
public static void main(String[] args) {
SpringApplication.run(testApplication.class,args);
}
}
我的存储库分类
package com.example.test.repository.ConfigRepository;
@Repository
public interface ConfigRepository extends MongoRepository<Config,String>,QuerydslPredicateExecutor<Config> {
}
这是我在调试模式下遇到的错误
DEBUG oscaClasspathBeanDeFinitionScanner-被忽略,因为不是具体的顶级类:文件[/ opt / / /target/classes/com/example/test/repository/ConfigRepository.class]
@import中使用的AutoConfig类如下
package com.example.common;
@Configuration
@EnableFeignClients
@ComponentScan({ "com.example.common" })
public class AutoConfig {
解决方法
您在此软件包中的 ConfigRepository
中的 com.example.test.repository
类。
在提供 @ComponentScan
的同时,您正在通过此路径 com.example.common
。
因此,您没有尝试使用此 com.example.test
路径,如下所示。
还可以在您的 SpringBootApplication
文件或 Config
文件中提供 EnableMongoRepositories
并设置 basePackages
属性。
package com.example.test;
@Import({ AutoConfig.class })
@EnableMongoRepositories(basePackages = {"com.example.test.repository"})
@SpringBootApplication
public class testApplication {
public static void main(String[] args) {
SpringApplication.run(testApplication.class,args);
}
}
@Configuration
@EnableFeignClients
@ComponentScan({ "com.example.test" })
public class AutoConfig {
有关 @EnableMongoRepositories
的更多信息,您将从here了解到一个想法。
这将为您提供帮助。