I'm trying to configure spring boot to set my test datasource to use h2 in postgresql mode. I set these lines in my test/resources/application:
spring.datasource.url=jdbc:h2:mem:db1;MODE=PostgreSQL
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=
But spring boot keep loading me default h2 configuration.
How can I force spring boot to use my special h2 configuration ?
just do it in java-configuration like this:
@Configuration
@EnableAutoConfiguration
@Profile({ "dev", "demo" })
public class EmbeddedDatabaseConfiguration {
@Bean(name = "dataSource")
public DriverManagerDataSource getDataSource() {
DriverManagerDataSource driverManagerDataSource = new DriverManagerDataSource();
driverManagerDataSource.setDriverClassName("org.h2.Driver");
driverManagerDataSource.setUrl("jdbc:h2:mem:mylivedata;IGNORECASE=TRUE;DB_CLOSE_ON_EXIT=FALSE;DB_CLOSE_DELAY=-1");
return driverManagerDataSource;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.