【发布时间】:2019-07-08 14:40:16
【问题描述】:
我正在尝试遵循 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;
}
}
按照建议更新包结构:
【问题讨论】:
-
已按照@sfat 和 Wim Deblauwe 的建议进行了更新。仍然有同样的错误
标签: java spring spring-boot