简体   繁体   English

在 STS 中运行 Spring Boot 应用程序时找不到 Bean

[英]Bean could not be found when running Spring Boot application in STS

I get this when I try to run my Spring Boot application in STS:当我尝试在 STS 中运行我的 Spring Boot 应用程序时,我得到了这个:

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

Description:

Parameter 1 of constructor in com.greglturnquist.learningspringboot2.learningspringboot2.ImageService required a bean of type 'com.greglturnquist.learningspringboot2.learningspringboot2.ImageRepository' that could not be found.


Action:

Consider defining a bean of type 'com.greglturnquist.learningspringboot2.learningspringboot2.ImageRepository' in your configuration.

I tried adding我尝试添加

compile ("com.greglturnquist.learningspringboot2.learningspringboot2.ImageRepository")

to build.gradle but that's made no difference.build.gradle但这没有区别。 How do I resolve this?我该如何解决?

This is my ImageRepository class:这是我的 ImageRepository 类:

package com.greglturnquist.learningspringboot2.learningspringboot2;

import org.springframework.data.repository.reactive.ReactiveCrudRepository;
import reactor.core.publisher.Mono;

public interface ImageRepository extends ReactiveCrudRepository<Image, String> {

    Mono<Image> findByName(String name);

}

Please add @Repository to your class and run.请将@Repository 添加到您的班级并运行。

@Repository
public interface ImageRepository extends ReactiveCrudRepository<Image, String> {

    Mono<Image> findByName(String name);

}

Update: And also include @EnableJpaRepositories above your configuration or SpringBootApplication class to include those in component scan.更新:并且还在您的配置或 SpringBootApplication 类上方包含 @EnableJpaRepositories 以将那些包含在组件扫描中。

You forgot to add @Repository anotation to you class.您忘记在类中添加 @Repository 注释。

@Repository
public interface ImageRepository extends ReactiveCrudRepository<Image, String> {

}

Kindly add it and hopefully it will solve your problem.请添加它,希望它能解决您的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM