如何解决没有类型为'com.example.test.repository.ConfigRepository'的合格Bean:预期至少有1个Bean可以自动接线

问题描述

以下是我的目录结构

  1. com.example
  2. com.example.common
  3. com.example.test
  4. 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了解到一个想法。 这将为您提供帮助。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...