I have such repository:
public interface ApartmentRepository
extends PagingAndSortingRepository<Apartment, Long> {
Page<LandlordPageApartment> findAllByOwnerId(long ownerId, Pageable pageable);
}
And when I use it, there is an exception: org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [Apartment] to type [LandlordPageApartment]
Here I define my converter:
@Component
public class ApartmentToLandlordPageApartmentConverter implements Converter<Apartment, LandlordPageApartment> {
@Override
public LandlordPageApartment convert(Apartment apartment) {
// some conversion
}
}
Converter registration:
@Configuration
@EnableWebMvc
public class AbsWebMvcConfigurer implements WebMvcConfigurer {
@Override
public void addFormatters(FormatterRegistry registry) {
registry.addConverter(apartmentToLandlordPageApartmentConverter());
}
@Bean
public ApartmentToLandlordPageApartmentConverter
apartmentToLandlordPageApartmentConverter() {
return new ApartmentToLandlordPageApartmentConverter();
}
// ...
}
What I do wrong?