定义类型 bean 的问题

时间:2021-06-03 17:19:59

标签: java spring-boot spring-mvc annotations

我尝试通过使用注释@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.

项目结构如下:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

com.example.learn 

包装

在上面你不需要@ComponentScan 和@Repository 因为@SpringBootApplication 会处理它。