Spring не может найти в проекте репозиторий
При недавней загрузки приложения из Idea стала вылетать ошибка, хотя раньше было все в порядке и при деплое на heroku все запускается нормально.
***************************
APPLICATION FAILED TO START
***************************
Description:
Parameter 3 of constructor in com.melky.bot.vk.handlers.CallbackAPIHandler required a bean of type 'com.melky.bot.vk.repos.ElementToDoListRepo' that could not be found.
Action:
Consider defining a bean of type 'com.melky.bot.vk.repos.ElementToDoListRepo' in your configuration.
Сам код, где используются репозитории
@Component
public class CallbackAPIHandler {
private VKBot vkBot;
private Weather weather;
private KeyboardHandler keyboardHandler;
@Value("${vk.confCode}")
private String confirmationCode;
private UserRepo userRepo;
private ElementToDoListRepo elementRepo;
private final Gson gson = new Gson();
private TransportClient transportClient;
private VkApiClient vk;
private GroupActor groupActor;
public CallbackAPIHandler(@Lazy VKBot vkBot, Weather weather, KeyboardHandler keyboardHandler, UserRepo userRepo, ElementToDoListRepo elementRepo) {
this.vkBot = vkBot;
this.weather = weather;
this.keyboardHandler = keyboardHandler;
this.userRepo = userRepo;
this.elementRepo = elementRepo;
}
//Много не нужного кода
}
Сами репозитории:
@Repository
public interface UserRepo extends CrudRepository<User, Long> {
}
@Repository
public interface ElementToDoListRepo extends CrudRepository<ElementToDoList, Long> {
}
Решения еще не нашел, аннотации @EnableJpaRepositories не помогли.
Ответы (1 шт):
Автор решения: Sergey Mitrofanov
→ Ссылка
Все верно. Репозиторий поднимает бин с именем elementToDoListRepo, а вы пытаетесь инъектить elementRepo, которого нет.
Или переименуйте переменную в elementToDoListRepo, или используйте Qualifier.
@Repository
@Qualifier("elementRepo")
public interface ElementToDoListRepo extends CrudRepository<ElementToDoList, Long> {
}