title: Spring Boot Configuration Class vs. Properties during Test
body: <p>I have little experience with the autoconfiguration of Spring Boot. What is the best practice in dealing with the database configuration for the production and the test.</p>
  
  <p>Currently I have a configuration for the production which reads the database properties from a propertie file. What is the difference or what is the configuration for the entity manager. I do not create a bean but only specify the key value pairs in the file.</p>
  
  <p>For the test, however, I have to create the beans, otherwise the message comes:</p>
  
  <blockquote>
    <p>Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'entityManagerFactory' available</p>
  </blockquote>
  
  <p>Currently my test class is as follows:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @ContextConfiguration(locations = { "classpath:test-context.xml" })
  @AutoConfigureTestDatabase(connection = EmbeddedDatabaseConnection.H2)
  @EnableTransactionManagement
  @EnableJpaRepositories(basePackages = "de.xxx.xxx", repositoryBaseClass = 
                                                  ExtendedRepositoryImpl.class)
  @EntityScan(basePackages = { "de.xxx.xxx" })
  @ComponentScan(basePackages = { "de.xxx.xxx" })
  @EnableJpaAuditing
  @ActiveProfiles(profiles = { "test" })
  public abstract class AbstractTestCase {
  
  protected static final Log LOG = LogFactory.getLog(AbstractTestCase.class);
  }
  </code></pre>
  
  <p>So what is the best in dealing with the configuration. In Java within the @Configuration or per propertie file? When should I use something?</p>
  
  <p><strong>UPDATE 1:</strong>
  I added the @DataJpaTest annotation and remove the @Bean's from the @Configuration class. It still works, but what is the best practis to deal with? Is there a guide to understand the magic of the annotations?</p>