【发布时间】:2017-09-15 23:38:42
【问题描述】:
我在将 spring 与 h2 结合使用时遇到问题。我使用 h2 数据库进行测试,但我的行为非常奇怪。
我的依赖:
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
...
我将我的测试的 jdbc 连接字符串设置为:
spring.datasource.url=jdbc:h2:mem:dataSource
不考虑基本测试:
@RunWith(SpringRunner.class)
@SpringBootTest
public class DemoApplicationTests {
@Test
public void contextLoads() {
}
}
如果我跑步
mvn 测试
在我的 pom 所在的同一目录中,一切正常。但是如果在父目录执行这个命令
mvn -f ./xxx/pom.xml 测试
测试没有成功。
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [org/springframework/boot/autoconfigure/orm/jpa/HibernateJpaAutoConfiguration.class]: Invocation of init method failed; nested exception is javax.persistence.PersistenceException: Unable to resolve persistence unit root URL
如何在父目录中运行测试?
【问题讨论】:
标签: java spring maven spring-data h2