title: Spring boot 2 : ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date]
body: <p>I use spring-boot 2.</p>
  
  <p>I my Junit test (<code>@SpringBootTest</code>), i use a <code>org.springframework.test.web.servlet.MockMvc</code></p>
  
  <pre><code>@Test
  @WithMockUser(roles = {"ADMIN"})
  public void testGetSearchByFoodIdWithAdmin() throws Exception {
      final ResultActions resultActions = mockMvc.perform(get(RESOURCE_URL + "/search/findByFooId?fooId=123"))
                  .andExpect(status().isOk());
  }
  </code></pre>
  
  <p><strong>I have this Converter:</strong></p>
  
  <pre><code>public class ZonedDateTimeToDateConverter implements Converter&lt;ZonedDateTime, Date&gt; {
      @Override
      public Date convert(final ZonedDateTime source) {
          return source == null ? null : Date.from(source.toInstant());
      }
  }
  </code></pre>
  
  <p><strong>I have this other Converter:</strong></p>
  
  <pre><code>public class DateToZonedDateTimeConverter implements Converter&lt;Date, ZonedDateTime&gt; {
      @Override
      public ZonedDateTime convert(final Date source) {
          return source == null ? null : ofInstant(source.toInstant(), systemDefault());
      }
  }
  </code></pre>
  
  <p><strong>I have this Spring configuration:</strong></p>
  
  <pre><code>@Configuration
  @EnableMongoAuditing(dateTimeProviderRef = "dateTimeProvider")
  public class MongoConfiguration {
  
      @Autowired
      MongoDbFactory mongoDbFactory;
  
      @Bean
      public MongoCustomConversions customConversions() {
          List&lt;Converter&lt;?, ?&gt;&gt; converters = new ArrayList&lt;&gt;();
          converters.add(new DateToZonedDateTimeConverter());
          converters.add(new ZonedDateTimeToDateConverter());
          return new MongoCustomConversions(converters);
      }
  
      @Bean
      public MongoTemplate mongoTemplate() throws Exception {
          MappingMongoConverter converter = getDefaultMongoConverter();
          //converter.afterPropertiesSet();
          MongoTemplate mongoTemplate = new MongoTemplate(mongoDbFactory, converter);
          return mongoTemplate;
      }
  
      @Bean
      public MappingMongoConverter getDefaultMongoConverter() throws Exception {
          MappingMongoConverter converter = new MappingMongoConverter(
                  new DefaultDbRefResolver(mongoDbFactory), new MongoMappingContext());
          converter.setCustomConversions(customConversions());
          return converter;
      }
  
  }
  </code></pre>
  
  <p><strong>I have this other Spring configuration:</strong></p>
  
  <pre><code>@Component
  public class MyWebMvcConfigurer extends WebMvcConfigurerAdapter {
  
      @Override
      public void addFormatters(FormatterRegistry registry) {
          registry.addConverter(new DateToZonedDateTimeConverter());
          registry.addConverter(new ZonedDateTimeToDateConverter());
      }
  
  }
  </code></pre>
  
  <p><strong>I have this error:</strong></p>
  
  <pre><code>org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.time.ZonedDateTime] to type [java.util.Date]
  </code></pre>
  
  <p>Why my converter is not taken into account for the WebMvc part while for MongoDB it's good?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>I use Spring Data Rest</p>
  
  <pre><code>@RepositoryRestResource(collectionResourceRel = "foo", path = "foo")
  public interface FooRepository extends MongoRepository&lt;Foo, String&gt; {
  
      Foo findByFooId(@Param("fooId") String fooId);
  
  }
  </code></pre>
  
  <p>My <code>Foo</code>class:</p>
  
  <pre><code>@Document
  @NoArgsConstructor
  @AllArgsConstructor
  @Builder
  @Data
  public class Foo {
  
      @Id
      private String keyid;
  
      @NotNull
      private String fooId;
  
      @CreatedDate
      @JsonProperty(access = JsonProperty.Access.READ_ONLY)
      private ZonedDateTime creationDate;
  
      @LastModifiedDate
      @JsonProperty(access = JsonProperty.Access.READ_ONLY)
      private ZonedDateTime updateDate;
  }
  </code></pre>
  
  <p><strong>EDIT n°2:</strong></p>
  
  <p>I try it with <code>CustomizedRestMvcConfiguration</code> implements RepositoryRestConfigurer` but not sole my problem:</p>
  
  <pre><code>@Configuration
  @EnableWebMvc
  public class CustomizedRestMvcConfiguration implements RepositoryRestConfigurer {
  
      @Bean
      public DateToZonedDateTimeConverter dateToZonedDateTimeConverter() {
          return new DateToZonedDateTimeConverter();
      }
  
      @Bean
      public ZonedDateTimeToDateConverter zonedDateTimeToDateConverter() {
          return new ZonedDateTimeToDateConverter();
      }
  
      @Override
      public void configureConversionService(ConfigurableConversionService conversionService) {
          conversionService.addConverter(dateToZonedDateTimeConverter());
          conversionService.addConverter(zonedDateTimeToDateConverter());
      }
  
  }
  </code></pre>