当我尝试在 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.
我尝试添加
compile ("com.greglturnquist.learningspringboot2.learningspringboot2.ImageRepository")
到build.gradle
但这没有什么区别。我该如何解决这个问题?
这是我的 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);
}
最佳答案
请将@Repository添加到您的类中并运行。
@Repository
public interface ImageRepository extends ReactiveCrudRepository<Image, String> {
Mono<Image> findByName(String name);
}
更新: 并且还在您的配置或 SpringBootApplication 类上方添加 @EnableJpaRepositories 以将其包含在组件扫描中。
关于java - 在STS中运行Spring Boot应用程序时找不到Bean,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59597853/