![](/img/trans.png)
[英]when running spring Boot application getting required a bean of type that could not be found
[英]Bean could not be found when running 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.
我嘗試添加
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 以將那些包含在組件掃描中。
您忘記在類中添加 @Repository 注釋。
@Repository
public interface ImageRepository extends ReactiveCrudRepository<Image, String> {
}
請添加它,希望它能解決您的問題。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.