【发布时间】:2017-10-23 09:02:03
【问题描述】:
我正在尝试创建一个使用嵌入式 H2 数据库的测试。但是我必须更改 spring.datasource.url,我不能使用 spring boot 创建的默认值。 (这是因为我得把H2数据库的模式改成MYSQL)
这是我的test class:
@JdbcTest
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
public class DemoApplicationTests {
@Autowired
JdbcTemplate jdbcTemplate;
@Autowired
DataSource dataSource;
@Test
public void contextLoads() {
System.out.println(dataSource);
}
}
这是我的application-test.properties:
spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;MODE=MYSQL
spring.datasource.username=dbuser
spring.datasource.password=dbpass
我的依赖:
compile('org.springframework.boot:spring-boot-starter-batch')
runtime('com.h2database:h2')
compile group: 'org.springframework.boot', name: 'spring-boot-starter-jdbc', version: '1.5.3.RELEASE'
compile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '1.5.3.RELEASE'
控制台输出:
启动嵌入式数据库:url='jdbc:h2:mem:bfad6b71-3e2d-4a47-a32d-c76988b3c5f6;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=false', username='sa'
我希望 url 是这样的:jdbc:h2:mem:testdb,我还希望它采用 MODE=MYSQL 设置。
我尝试关注this post,但没有成功。
【问题讨论】:
标签: java spring spring-boot junit h2