title: How to prevent spring boot from auto creating instance of bean 'entityManagerFactory' at startup?
body: <p>I am working on a Spring boot application that uses <code>Spring JPA</code> with <code>PostgreSQL</code>. I am using <code>@SpringBootTest(classes = &lt;my package&gt;.Application.class)</code> to initialize my unit test for a controller class. </p>
  
  <p>The problem is that this is causing the <code>entityManagerFactory</code> bean (and many other objects related to jpa, datasource, jdbc, etc.) to be created which is not needed for unit tests. Is there a way to prevent Spring from automatically creating these objects till they are actually used the first time? </p>
  
  <p>I spent a lot of time trying to load up only the beans I need for my unit test but ran into many errors. I am relatively new to Spring and I am hoping someone else has run into this before...and can help. I can post code snippets if needed.</p>
  
  <p><strong>Update:</strong> I am not sure if I should edit or answer my own question...choosing to edit since I ended up changing my approach to unit tests. I added this to my test config class.</p>
  
  <pre><code>  @Configuration
    @ComponentScan(basePackages = {"api.controller", "api.config", "api.utils"})
    public class TestControllerConfig {
    }
  </code></pre>
  
  <p>and I mocked out the service and repository classes.</p>