While I was using Spring Boot 1.5, on application startup Hibernate executed schema.sql file located in /resources folder when appropriate configuration is
If you load a database that is not embedded, in Spring Boot 2 you need to add:
spring.datasource.initialization-mode=always
Check the Migration Guide:
Database Initialization
Basic DataSource initialization is now only enabled for embedded data sources and will switch off as soon as you’re using a production database. The new
spring.datasource.initialization-mode(replacingspring.datasource.initialize) offers more control.
I once had a similar problem, even though it was an h2 (so it was an embedded DB), my h2 configuration was activated by a my-test profile.
My test class was like:
@RunWith(SpringRunner.class)
@SpringBootTest // does not work alone
@ActiveProfiles("my-test")
public class MyEntityRepositoryTest {
The problem is @SpringBootTest alone did not initialize the test database. I had to either use @DataJpaTest or @SpringBootTest+@AutoConfigureTestDatabase. Examples
@RunWith(SpringRunner.class)
@DataJpaTest // works
@ActiveProfiles("sep-test")
public class MyEntityRepositoryTest {
or
@RunWith(SpringRunner.class)
@SpringBootTest // these two
@AutoConfigureTestDatabase // together work
@ActiveProfiles("sep-test")
public class MyEntityRepositoryTest {