title: Unable to use findOne(example) in Spring Data JPA unit tests
body: <p>I have a postgres production database, and my unit tests use H2. I just added some JPA repositories that use the JPA <code>findOne(Example example)</code>, and now my unit tests are erroring with the message "No property example found for type". </p>
  
  <p>I have a custom repository like this:</p>
  
  <pre><code>@NoRepositoryBean
  public interface RefDataRepository&lt;Model, Id&gt; extends JpaRepository&lt;Model, Id&gt; {
      Model findOrCreateByExample(Example&lt;Model&gt; example);
  }
  
  public class RefDataRepositoryImpl&lt;Model, Id&gt; extends SimpleJpaRepository&lt;Model, Id&gt; implements RefDataRepository&lt;Model, Id&gt; {
      public RefDataRepositoryImpl(JpaEntityInformation&lt;Model, ?&gt; entityInformation, EntityManager entityManager) {
          super(entityInformation, entityManager);
      }
  
      @Override
      @Transactional
      public Model findOrCreateByExample(Example&lt;Model&gt; example) {
          Optional&lt;Model&gt; existing = findOne(example);
          return existing.orElseGet(() -&gt; save(example.getProbe()));
      }
  }
  </code></pre>
  
  <p>And my JPA repositories are simply:</p>
  
  <pre><code>public interface MyRefRepository extends RefDataRepository&lt;MyRef, Integer&gt; {}
  </code></pre>
  
  <p>In production code, this works as I'd expect: the <code>findOne</code> method is called with the Example, and if it's not found, then it gets the probe out and saves that instance. But my unit tests completely die when setting up the test application context.</p>
  
  <p>All of my unit tests have annotations similar to this:</p>
  
  <pre><code>@ActiveProfiles("test")
  @ExtendWith(SpringExtension.class)
  @SpringBootTest
  @ContextConfiguration( classes = { TestDataSourceConfiguration.class, MyApplication.class })
  </code></pre>
  
  <p>And <code>TestDataSourceConfiguration</code> is functionally identical to the equivalent in the production code, setting up the data source. (Eg. in test it's configuring the in-memory H2 database.) It does include the following annotations:</p>
  
  <pre><code>@EnableJpaRepositories(
          entityManagerFactoryRef = "entityManagerFactory",
          transactionManagerRef = "transactionManager",
          basePackages = {"com.example.services"},
          repositoryBaseClass = RefDataRepositoryImpl.class
  )
  </code></pre>
  
  <p>(My production code similarly declares RefDataRepositoryImpl as the repository base class.)</p>
  
  <p>I don't even get to the actual meat of the unit tests, so that's not relevant. But every test I use the <code>@SpringBootTest</code> annotation on has the same issue, along with <code>@DataJpaTest</code>.</p>
  
  <pre><code>Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract com.example.models.MyRef com.example.services.RefDataRepository.findOrCreateByExample(org.springframework.data.domain.Example)! No property example found for type MyRef !
      at org.springframework.beans.factory.support.ConstructorResolver.createArgumentArray(ConstructorResolver.java:769) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:509) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1321) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1160) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:555) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:515) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$0(AbstractBeanFactory.java:320) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:222) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:318) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:199) ~[spring-beans-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1105) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:867) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:549) ~[spring-context-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:775) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
      at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
      at org.springframework.boot.SpringApplication.run(SpringApplication.java:316) ~[spring-boot-2.1.4.RELEASE.jar:2.1.4.RELEASE]
      at org.springframework.boot.test.context.SpringBootContextLoader.loadContext(SpringBootContextLoader.java:127) ~[spring-boot-test-2.1.4.RELEASE.jar:2.1.4.RELEASE]
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContextInternal(DefaultCacheAwareContextLoaderDelegate.java:99) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:117) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.support.DefaultTestContext.getApplicationContext(DefaultTestContext.java:108) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.web.ServletTestExecutionListener.setUpRequestContextIfNecessary(ServletTestExecutionListener.java:190) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.web.ServletTestExecutionListener.prepareTestInstance(ServletTestExecutionListener.java:132) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.TestContextManager.prepareTestInstance(TestContextManager.java:246) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.springframework.test.context.junit.jupiter.SpringExtension.postProcessTestInstance(SpringExtension.java:97) ~[spring-test-5.1.6.RELEASE.jar:5.1.6.RELEASE]
      at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$5(ClassTestDescriptor.java:349) ~[junit-jupiter-engine-5.3.2.jar:5.3.2]
      at org.junit.jupiter.engine.descriptor.JupiterTestDescriptor.executeAndMaskThrowable(JupiterTestDescriptor.java:215) ~[junit-jupiter-engine-5.3.2.jar:5.3.2]
      at org.junit.jupiter.engine.descriptor.ClassTestDescriptor.lambda$invokeTestInstancePostProcessors$6(ClassTestDescriptor.java:349) ~[junit-jupiter-engine-5.3.2.jar:5.3.2]
      at java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:193) ~[?:1.8.0_161]
      at java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:175) ~[?:1.8.0_161]
  </code></pre>
  
  <p>How can I get my unit tests to recognize that Example is not a property but rather part of the Spring Data JPA magic? This is the only place where I use Example. The test database is simple h2 in-memory.</p>