java - 没有可用的“repository.PersonRepository”类型的合格 bean
问题描述
我正在尝试遵循 Spring Boot 示例,我在互联网上搜索了几个小时,但没有找到解决我的案例的方法。大多数解决方案我发现他们说要使用@ComponentScan 来扫描包,我是否遗漏了什么,任何 hep 表示赞赏。
SpringBootApplication 类:
package ben;
@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan({"services","repository", "web"})
public class SpringBootWebApplication
{
public static void main (String [] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
}
PersonRepository 类:
package ben.repository;
@Repository
public interface PersonRepository extends CrudRepository<Bde, Integer> {
}
人员服务:
package ben.services;
import models.Bde;
public interface PersonService
{
public Iterable <Bde> findAll();
}
PersonServiceImpl:
package ben.services;
@Service
public class PersonServiceImpl implements PersonService
{
@Autowired
private PersonRepository personRepository;
@Override
public Iterable<Bde> findAll()
{
return personRepository.findAll();
}
}
PersonRest 类:
package ben.web;
@RestController
public class PersonRest
{
@Autowired
//@Qualifier("PersonServiceImpl")
private PersonService personService;
@RequestMapping("/person")
@ResponseBody
public Iterable <Bde> findAll() {
Iterable <Bde> persons=personService.findAll();
return persons;
}
}
包结构更新如建议:
解决方案
您只是在扫描您的服务包。
尝试这个...
@ComponentScan(basePackages = { "services", "repository" })
推荐阅读
- c++ - 矩形类中没有匹配函数
- uvm - 如何使用 p_sequencer 按顺序访问 sequencer 中的方法?
- c# - mvvm 解决嵌套模型和视图模型
- mongodb - 嵌入式文档中的 MongoDB 嵌套查找
- php - 如何恢复 Plesk Cpanel 文件
- javascript - Chart.js中x轴上的自定义标签/固定范围用于水平条形图?
- javascript - 根据 Gatsby 中的 url 更改字体颜色
- visual-studio-code - 如何在 VS Code 中更改终端的语言
- spring - 无法将 thymeleaf springsecurity 或布局方言添加到我的应用程序
- c# - 使用 Gremlin.net 读取/保存文件