Ошибка прокси или что-то типо того

Выдаёт ошибку :

Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'logOutUserService' defined in file [C:\Users\29857\IdeaProjects\Training-Team-2\build\classes\java\main\com\trainingApplication\core\service\LogOutUserService.class]: Unsatisfied dependency expressed through constructor parameter 0; nested exception is org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'hibernateUserRepository' is expected to be of type 'com.trainingApplication.repository.user.HibernateUserRepository' but was actually of type 'jdk.proxy2.$Proxy59'

Сервис использует репозиторий, который имплементирует интерфейс с generic методами. Вызывать конкретно интерфейс (DefaultRepository) не хочется, потому необходимо сделать его общим для нескольких сущностей и в имплементациях использовать общие, а также дополнительные методы. В чём может быть проблема и можно ли так вообще сделать? Бины все расставлены.

Сам сервис, который вызвает репозиторий:

private final HibernateUserRepository repository;

Репозиторий:

public class HibernateUserRepository implements DefaultRepository<UserEntity> 

Ну и сам интерфейс:

public interface DefaultRepository<T> {

    T save(T entity);

    List<T> findAll();

    boolean remove(T entity);

    T getEntityById(Long id);

}

Ответы (1 шт):

Автор решения: ulxanxv

Ощущение, что у вас какая то неверная конфигурация приложения. Если всё делать правильно, то никакой ошибки с таким кодом не будет. Он абсолютно верный.

Controller

@RestController
@RequestMapping("/rest")
@RequiredArgsConstructor
public class MController {

    private final HibernateUserRepository hibernateUserRepository;

    @GetMapping("/find-all")
    public List<UserEntity> test() {
        return hibernateUserRepository.findAll();
    }

}

DefaultRepository

public interface DefaultRepository<T> {

    T save(T entity);

    List<T> findAll();

    boolean remove(T entity);

    T getEntityById(Long id);

}

HibernateUserRepository

@Repository
public class HibernateUserRepository implements DefaultRepository<UserEntity> {

    @Override
    public UserEntity save(UserEntity entity) {
        return null;
    }

    @Override
    public List<UserEntity> findAll() {
        return Collections.singletonList(getDummy());
    }

    @Override
    public boolean remove(UserEntity entity) {
        return false;
    }

    @Override
    public UserEntity getEntityById(Long id) {
        return null;
    }

    private UserEntity getDummy() {
        final UserEntity userEntity = new UserEntity();
        userEntity.setName("Andrey");
        userEntity.setAge("15");
        userEntity.setSkills(Collections.singletonList("Spring"));

        return userEntity;
    }

}

UserEntity

import lombok.Data;

import java.util.List;

@Data
public class UserEntity {

    private String name;
    private String age;
    private List<String> skills;

}

Ответ от сервиса вернулся корректный
введите сюда описание изображения

→ Ссылка