how to solve No qualifying bean of type 'com.example.test.repository.ConfigRepository' available: expected at least 1 bean which qualifies autowire

huangapple go评论81阅读模式
英文:

how to solve No qualifying bean of type 'com.example.test.repository.ConfigRepository' available: expected at least 1 bean which qualifies autowire

问题

以下是我的目录结构

  1. com.example
  2. com.example.common
  3. com.example.test
  4. com.example.test.repository

我的主要 Spring Boot 类如下

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 o.s.c.a.ClassPathBeanDefinitionScanner - 由于不是具体的顶层类,因此被忽略:文件 [/opt/<folder_name>/<folder_name>/target/classes/com/example/test/repository/ConfigRepository.class]

在@Import中使用的 AutoConfig 类如下

package com.example.common;

@Configuration
@EnableFeignClients
@ComponentScan({ "com.example.common" })
public class AutoConfig {
英文:

Following is my directory structure

  1. com.example
  2. com.example.common
  3. com.example.test
  4. com.example.test.repository

my main spring boot class is as follow

package com.example.test;

@Import({ AutoConfig.class })
@SpringBootApplication
public class testApplication {
  public static void main(String[] args) {
	SpringApplication.run(testApplication.class, args);
  }
}

my repository clas

package com.example.test.repository.ConfigRepository;

 @Repository
 public interface ConfigRepository extends MongoRepository&lt;Config, String&gt;, QuerydslPredicateExecutor&lt;Config&gt; {

}

This is the error i am getting in debug mode

DEBUG o.s.c.a.ClassPathBeanDefinitionScanner - Ignored because not a concrete top-level class: file [/opt/<folder_name>/<folder_name>/target/classes/com/example/test/repository/ConfigRepository.class]

AutoConfig class used in @import is as below

package com.example.common;

@Configuration
@EnableFeignClients
@ComponentScan({ &quot;com.example.common&quot; })
public class AutoConfig {

答案1

得分: 1

你的 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 的更多信息,你可以从这里了解到。

这会对你有所帮助。

英文:

Your ConfigRepository class in in com.example.test.repository this package.

and while providing @ComponentScan, you are passing this path com.example.common.

So instead of that you just tried with this com.example.test path as below.

And also on your SpringBootApplication file or on your Config file you can provide EnableMongoRepositories and setting basePackages attributes.

package com.example.test;

@Import({ AutoConfig.class })
@EnableMongoRepositories(basePackages = {&quot;com.example.test.repository&quot;})
@SpringBootApplication
public class testApplication {
  public static void main(String[] args) {
    SpringApplication.run(testApplication.class, args);
  }
}

@Configuration
@EnableFeignClients
@ComponentScan({ &quot;com.example.test&quot; })
public class AutoConfig {

More about @EnableMongoRepositories you will get an idea from here.
This will help you.

huangapple
  • 本文由 发表于 2020年9月5日 16:43:18
  • 转载请务必保留本文链接:https://go.coder-hub.com/63752052.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定