title: How to exclude @EnableJpaRepositories from test?
body: <p>I have a main <code>@SpringBootApplication</code> which needs to scan a specific package in order to enable the JPA repositories, so I use <code>@EnableJpaRepositories</code> to specify that. Right now I'm implementing unit tests and I want to test the Controller component only, so I followed the tutorial in the official docs where they use <code>@WebMvcTest(MyController.class)</code> to test a controller with a service dependency.
  The problem is that this is not working for me because it is trying to load the JpaRepositories that I specify in the main Spring Boot application (when I comment the <code>@EnableJpaRepositories</code> in the main class the test runs without problem).</p>
  <p>I'm guessing I need to create a specific configuration for the test class so it can ignore the main configuration (since I only want to load the Controller and mock the service layer), but I don't know how to create such. I tried adding an empty configuration, but it is still failing with the same error:</p>
  <pre><code>@TestConfiguration
  static class TestConfig {}
  </code></pre>
  <p>This is the error I get:</p>
  <pre><code>Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'failureTaskHandler': Unsatisfied dependency expressed through field 'myManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'msgManager': Unsatisfied dependency expressed through field 'inboundManager'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'inboundManager': Unsatisfied dependency expressed through field 'messageRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'messageRepository' defined in com.example.MessageRepository defined in @EnableJpaRepositories declared on MonitorApplication: Cannot create inner bean '(inner bean)#45e639ee' of type [org.springframework.orm.jpa.SharedEntityManagerCreator] while setting bean property 'entityManager'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name '(inner bean)#45e639ee': Cannot resolve reference to bean 'entityManagerFactory' while setting constructor argument; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available
  </code></pre>
  <p>And my test class:</p>
  <pre><code>@WebMvcTest(MyController.class)
  public class MyControllerTest {
  
    @Autowired private MockMvc mvc;
  
    @MockBean private MyService service;
  
  
    // Tests here
  
    // @Test
    // public void...
  
  
  }
  </code></pre>
  <p>MyController class:</p>
  <pre><code>@RestController
  @CrossOrigin
  @RequestMapping(&quot;/api&quot;)
  @Slf4j
  public class MyController {
  
    @Autowired private MyService service;
  
    @PostMapping(value = &quot;/search&quot;, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
    public @ResponseBody SearchResponse getOrders(@RequestBody SearchRequest orderSearchRequest) {
      log.info(&quot;Receiving orders request...&quot;);
      return service.getOrders(orderSearchRequest);
    }
  
  }
  </code></pre>