Java 定义类型为的bean时遇到的问题

Java 定义类型为的bean时遇到的问题,java,spring-boot,spring-mvc,annotations,Java,Spring Boot,Spring Mvc,Annotations,我试图通过使用annotation@Repository扩展CRUD存储库来创建接口。我还尝试使用自动连线注释在服务类中使用接口函数。但我面临的问题如下 *************************** APPLICATION FAILED TO START *************************** Description: Field bookRepository in com.example.service.BookService required a bean of

我试图通过使用annotation@Repository扩展CRUD存储库来创建接口。我还尝试使用自动连线注释在服务类中使用接口函数。但我面临的问题如下

***************************
APPLICATION FAILED TO START
***************************

Description:

Field bookRepository in com.example.service.BookService required a bean of type 'com.example.repo.BookRepository' that could not be found.

The injection point has the following annotations:
    - @org.springframework.beans.factory.annotation.Autowired(required=true)


Action:

Consider defining a bean of type 'com.example.repo.BookRepository' in your configuration.
项目结构如下:


问题在于您的项目结构。尝试替换以下目录下的所有其他软件包:

com.example.learn 
包装


如下所述,您不需要@ComponentScan和@Repository,因为@SpringBootApplication会处理这些问题。

包括代码,但只要看一下您的项目结构,您似乎没有将主类包含在包含存储库的包中,而且看起来您没有
@EnableJpaRepositories
。(
@Repository
不需要,但Spring数据扫描是。)现在可以工作了,谢谢!