【发布时间】:2018-05-04 04:08:57
【问题描述】:
我在尝试启动我的应用程序时遇到此错误。我查看了许多类似的问题和主题,但似乎没有一个对我有帮助。
创建名为“databaseManager”的 bean 时出错:依赖关系不满足 通过字段“articleRepo”表示;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: 否 符合条件的 bean 类型 'pl.dzejkobdevelopment.database.repositories.ArticleRepo' 可用: 预计至少有 1 个 bean 有资格作为 autowire 候选者。依赖 注释: {@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'属性“实体管理器”;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名称为 '(inner bean)#14a1d6d' 的 bean 时出错:设置构造函数参数时无法解析对 bean 'entityManagerFactory' 的引用;嵌套异常是 org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
【问题讨论】:
标签: java spring hibernate jpa spring-data