Spring Paging and sorting репозиторий - Пользовательский конвертер - Не найден конвертер, способный конвертировать из типа в тип - PullRequest
0 голосов
/ 08 января 2019

У меня есть такое хранилище :

public interface ApartmentRepository
    extends PagingAndSortingRepository<Apartment, Long> {

    Page<LandlordPageApartment> findAllByOwnerId(long ownerId, Pageable pageable);

}

И когда я его использую, возникает исключение : org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [Apartment] to type [LandlordPageApartment]

Здесь я определяю мой конвертер :

@Component
public class ApartmentToLandlordPageApartmentConverter implements Converter<Apartment, LandlordPageApartment> {

    @Override
    public LandlordPageApartment convert(Apartment apartment) {
        // some conversion
    }

}

Регистрация преобразователя :

@Configuration
@EnableWebMvc
public class AbsWebMvcConfigurer implements WebMvcConfigurer {

    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(apartmentToLandlordPageApartmentConverter());
    }

    @Bean
    public ApartmentToLandlordPageApartmentConverter
    apartmentToLandlordPageApartmentConverter() {
        return new ApartmentToLandlordPageApartmentConverter();
    }
// ...
}

Что я делаю не так?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...