英文:
how to solve No qualifying bean of type 'com.example.test.repository.ConfigRepository' available: expected at least 1 bean which qualifies autowire
问题
以下是我的目录结构
- com.example
- com.example.common
- com.example.test
- 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
- com.example
- com.example.common
- com.example.test
- 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<Config, String>, QuerydslPredicateExecutor<Config> {
}
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({ "com.example.common" })
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 = {"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 {
More about @EnableMongoRepositories you will get an idea from here.
This will help you.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论