如何解决没有“com.example.test.repository.configrepository”类型的限定bean可用:至少需要1个限定autowire的bean

iyr7buue  于 2021-07-05  发布在  Java
关注(0)|答案(1)|浏览(482)

下面是我的目录结构
com.example公司
com.example.common公司
com.example.test测试
com.example.test.repository存储库
我的主要 Spring 靴类如下

  1. package com.example.test;
  2. @Import({ AutoConfig.class })
  3. @SpringBootApplication
  4. public class testApplication {
  5. public static void main(String[] args) {
  6. SpringApplication.run(testApplication.class, args);
  7. }
  8. }

我的知识库分类

  1. package com.example.test.repository.ConfigRepository;
  2. @Repository
  3. public interface ConfigRepository extends MongoRepository<Config, String>, QuerydslPredicateExecutor<Config> {
  4. }

这就是我在调试模式下遇到的错误
调试o.s.c.a.classpathbeandefinitionscanner-忽略,因为不是具体的顶级类:file[/opt/<folder\u name>/<folder\u name>/target/classes/com/example/test/repository/configrepository.class]
@import中使用的autoconfig类如下

  1. package com.example.common;
  2. @Configuration
  3. @EnableFeignClients
  4. @ComponentScan({ "com.example.common" })
  5. public class AutoConfig {
zbdgwd5y

zbdgwd5y1#

你的 ConfigRepository 上课时间 com.example.test.repository 这个包裹。
在提供 @ComponentScan ,您正在通过此路径 com.example.common .
所以你不是用这个吗 com.example.test 路径如下。
还有你的 SpringBootApplication 文件或在您的 Config 您可以提供的文件 EnableMongoRepositories 和设置 basePackages 属性。

  1. package com.example.test;
  2. @Import({ AutoConfig.class })
  3. @EnableMongoRepositories(basePackages = {"com.example.test.repository"})
  4. @SpringBootApplication
  5. public class testApplication {
  6. public static void main(String[] args) {
  7. SpringApplication.run(testApplication.class, args);
  8. }
  9. }
  10. @Configuration
  11. @EnableFeignClients
  12. @ComponentScan({ "com.example.test" })
  13. public class AutoConfig {

更多关于 @EnableMongoRepositories 你会从这里得到一个主意。这对你有帮助。

展开查看全部

相关问题