[英]Error creating bean with name : Unsatisfied dependency expressed through field
[英]Error creating bean with name : Unsatisfied dependency expressed
嘗試啟動我的應用時出現此錯誤。 我看過許多類似的問題和話題,但似乎沒有一個對我有幫助。
創建名稱為'databaseManager'的bean時出錯:通過字段'articleRepo'表示的不滿意依賴性; 嵌套的異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有類型為'pl.dzejkobdevelopment.database.repositories.ArticleRepo'的合格Bean:應該至少有1個有資格作為自動裝配候選的Bean。 依賴項注釋:{@ org.springframework.beans.factory.annotation.Autowired(required = true)}
@Repository
public interface ArticleRepo extends CrudRepository<Article, Long> {
}
和...
@Service
public class DatabaseManager {
@Autowired
private ArticleRepo articleRepo;
@Autowired
private CommentRepo commentRepo;
@Autowired
private TagRepo tagRepo;
@Autowired
private UserRepo userRepo;
public void addArticle(Article article){
article.getTags().forEach(tag ->addTag(tag));
articleRepo.save(article);
}
public List<Comment> findComments(User user){
return commentRepo.findByCommentAuthor(user);
}
private void addTag(Tag tag){
tagRepo.save(tag);
}
}
和...
@Configuration
//@ComponentScan(basePackages="pl.dzejkobdevelopment.database.repositories")
public class AppConfig {
@Bean
public WebsiteProporties websiteProporties(){
return new WebsiteProporties();
}
@Bean
public StorageProperties storageProporties(){ return new StorageProperties();}
@Bean
public DatabaseManager databaseManager(){ return new DatabaseManager();}
}
}
取消注釋ComponentScan
沒有幫助。
編輯量變到質變ComponentScan
為EnableJpaRepositories
給出了這樣的錯誤:
創建名稱為'databaseManager'的bean時出錯:通過字段'articleRepo'表示的不滿意依賴性; 嵌套異常是org.springframework.beans.factory.BeanCreationException:創建名稱為'articleRepo'的bean時出錯:設置bean時無法創建類型為[org.springframework.orm.jpa.SharedEntityManagerCreator]的內部bean'(inner bean)#14a1d6d'屬性“ entityManager”; 嵌套的異常是org.springframework.beans.factory.BeanCreationException:創建名稱為“((內部bean)#14a1d6d”)的bean時出錯:在設置構造函數參數時無法解析對bean'entityManagerFactory'的引用; 嵌套的異常是org.springframework.beans.factory.NoSuchBeanDefinitionException:沒有名為'entityManagerFactory'的bean可用
嘗試使用
@EnableJpaRepositories("pl.dzejkobdevelopment.database.repositories")
而不是ComponentScan。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.