0

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?

bovae
  • 312
  • 3
  • 12
  • Is your converter bean also registered as a `@Component`? – Makoto Jan 08 '19 at 19:35
  • @Makoto yes, but I think it does not matter. – bovae Jan 08 '19 at 19:36
  • Plz post the full stacktrace ... i found [a similar issue here on so](https://stackoverflow.com/q/53119756/592355), where (erroneously) `ConverterNotFoundException` pops up instead of something deeper. – xerx593 Jan 08 '19 at 19:54
  • @xerx593 sorry, but "It looks like your post is mostly code; please add some more details." – bovae Jan 08 '19 at 20:01

0 Answers0