使用 Spring JpaRepository 时,请考虑在 Spring Boot 的配置中定义一个类型的 bean

问题描述 投票:0回答:1

美好的一天,

我正在我的 Eclipse IDE 中做一个 Spring Boot 应用程序。当我右键单击 SpringBoot 应用程序文件并作为 Java 应用程序运行时,出现如下错误:


应用程序无法启动


描述:

com.utility.tool.ToolApplication 中的字段tutorialRepository 需要类型为“com.utility.tool.repository.TutorialRepository”的 bean,但无法找到。

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


Action:

Consider defining a bean of type 'com.utility.tool.repository.TutorialRepository' in your configuration.

然后我发现我忘记包含 spring boot starter data jar。因此,我在我的

build.gradle
中添加以下代码,它最终正确运行:

implementation 'org.springframework.boot:spring-boot-starter-data-jpa:2.7.5'

然后我右键单击我的项目并将jar导出为可运行jar,然后尝试通过

java -jar my.jar
运行它,它返回了错误。

我打开

JdGui
的罐子,发现
spring-boot-starter-data-jpa-2.7.5.jar
在里面。我可以知道我的错误是什么吗?我的 jar 结构如下:

罐子在列表中,但位于底部,因此不在我的屏幕截图中。

java spring spring-boot jparepository
1个回答
0
投票

检查您的 SpringBoot 注释。您可能缺少一些

@Service
@Repository
@Component
注释。

© www.soinside.com 2019 - 2024. All rights reserved.