title: Spring Data Rest: Intermittent Error with IllegalArgumentException
body: <p>Our Spring application is using Spring Data Rest for many of the application entities.  We are experiencing intermittent errors where all requests to the application will start failing with the following exception.   </p>
  
  <blockquote>
    <p>java.lang.IllegalArgumentException: Could not resolve repository metadata for [insert random entity].
    at org.springframework.data.rest.webmvc.config.ResourceMetadataHandlerMethodArgumentResolver.resolveArgument(ResourceMetadataHandlerMethodArgumentResolver.java:97)
        at org.springframework.data.rest.webmvc.config.RootResourceInformationHandlerMethodArgumentResolver.resolveArgument(RootResourceInformationHandlerMethodArgumentResolver.java:83)
        at org.springframework.data.rest.webmvc.config.RootResourceInformationHandlerMethodArgumentResolver.resolveArgument(RootResourceInformationHandlerMethodArgumentResolver.java:40)</p>
  </blockquote>
  
  <p>It's not easily reproducible and the message <em>Could not resolve repository metadata for [entity]</em> always refers to a random entity in our application.  This makes me think it's not a configuration problem on our end.  We are using version 2.1.3 of Spring Boot.  Any suggestions for troubleshooting?  Anyone else experiencing this?  </p>
  
  <p>For reference, the Spring code throwing the exception looks like this:</p>
  
  <pre><code>    public ResourceMetadata resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
      String lookupPath = this.baseUri.getRepositoryLookupPath(webRequest);
      String repositoryKey = UriUtils.findMappingVariable("repository", parameter.getMethod(), lookupPath);
      if (!StringUtils.hasText(repositoryKey)) {
          return null;
      } else {
          Iterator var7 = this.repositories.iterator();
  
          ResourceMetadata mapping;
          do {
              if (!var7.hasNext()) {
                  throw new IllegalArgumentException(String.format("Could not resolve repository metadata for %s.", repositoryKey));
              }
  
              Class&lt;?&gt; domainType = (Class)var7.next();
              mapping = this.mappings.getMetadataFor(domainType);
          } while(!mapping.getPath().matches(repositoryKey) || !mapping.isExported());
  
          return mapping;
      }
  }
  </code></pre>
  
  <p>I'm not sure what would suddenly make the repositories iterator suddenly become empty.</p>