【发布时间】:2019-12-10 09:01:30
【问题描述】:
使用 Spring boot 2 和 JUnit5 连接到 Neo4j 测试容器的问题
int 测试上下文。容器启动成功但是spring.data.neo4j.uri属性默认端口错误:7687,我猜这个URI在我调用neo4jContainer.getBoltUrl().的时候应该是一样的
在这种情况下一切正常:
@Testcontainers
public class ExampleTest {
@Container
private static Neo4jContainer neo4jContainer = new Neo4jContainer()
.withAdminPassword(null); // Disable password
@Test
void testSomethingUsingBolt() {
// Retrieve the Bolt URL from the container
String boltUrl = neo4jContainer.getBoltUrl();
try (
Driver driver = GraphDatabase.driver(boltUrl, AuthTokens.none());
Session session = driver.session()
) {
long one = session.run("RETURN 1",
Collections.emptyMap()).next().get(0).asLong();
assertThat(one, is(1L));
} catch (Exception e) {
fail(e.getMessage());
}
}
}
但 SessionFactory 不是按照这些建议使用自动配置为应用程序创建的 - https://www.testcontainers.org/modules/databases/neo4j/
当我尝试在测试上下文中创建自己的主 bean - SessionFactory 时,我收到这样的消息 - “在未加载容器之前无法返回 URI”
但应用程序使用自动配置和在容器中启动的 neo4j 可以完美运行和运行,测试上下文也无法告知
【问题讨论】:
标签: spring spring-boot spring-data-neo4j junit5