Reputation: 1
I'm getting this error while trying to start my app. I've looked at many similar problems and topics but none seems to help me.
Error creating bean with name 'databaseManager': Unsatisfied dependency expressed through field 'articleRepo'; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type 'pl.dzejkobdevelopment.database.repositories.ArticleRepo' available: expected at least 1 bean which qualifies as autowire candidate. Dependency annotations: {@org.springframework.beans.factory.annotation.Autowired(required=true)}
@Repository
public interface ArticleRepo extends CrudRepository<Article, Long> {
}
and...
@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);
}
}
and...
@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();}
}
}
Uncommenting ComponentScan
doesn't help.
EDIT
Changeing ComponentScan
for EnableJpaRepositories
gives this error:
Error creating bean with name 'databaseManager': Unsatisfied dependency expressed through field 'articleRepo'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'articleRepo': Cannot create inner bean '(inner bean)#14a1d6d' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#14a1d6d': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
Upvotes: 0
Views: 3352
Reputation: 147
Try to use
@EnableJpaRepositories("pl.dzejkobdevelopment.database.repositories")
instead of ComponentScan.
Upvotes: 0