【发布时间】:2017-07-11 04:51:30
【问题描述】:
我有一个 Spring Boot 应用程序,它有几个 @Entity 类和 @RepositoryRestResource 存储库接口。现在我想写一些测试,在那里我可以检查我是否可以使用这些存储库将新记录添加到我的数据库中,但我不想使用我配置的 MySQL 数据库,而是我想使用一些嵌入式数据库像H2。目前我有一个application.properties 文件,如下所示:
spring.jpa.hibernate.ddl-auto=create
spring.datasource.url=jdbc:mysql://localhost:3306/mydb
spring.datasource.username=root
spring.datasource.password=qwerty123
问题:如何配置我的应用以使用其他数据库进行测试?我的项目中没有xml,一切都基于注释。我尝试使用@Bean 定义@Configuration 类以创建DataSource,然后在测试类上将其与@ContextConfiguration 注释一起使用,但它说它无法加载上下文。
【问题讨论】:
标签: java mysql spring spring-boot junit