Java 等待0.0.0.0:8080,而不是本地主机:8080
在Java 等待0.0.0.0:8080,而不是本地主机:8080,java,scala,testcontainers,Java,Scala,Testcontainers,在GenericContainer类中,存在一个方法waitingFor,该方法等待状态代码200作为服务器的响应。 我正在容器中运行一个web应用程序,并使用0.0.0作为主机,而不是localhost。 当我尝试运行sbt测试时,我有以下超时: [sweetsoft/sapmock:latest] - Could not start container org.testcontainers.containers.ContainerLaunchException: Timed out wait
GenericContainer
类中,存在一个方法waitingFor
,该方法等待状态代码200
作为服务器的响应。我正在容器中运行一个web应用程序,并使用
0.0.0
作为主机,而不是localhost
。
当我尝试运行sbt测试时,我有以下超时:
[sweetsoft/sapmock:latest] - Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for container port to open (localhost ports: [8080] should be listening)
我使用的测试容器如下所示:
final class MessageSpec extends BddSpec
with ForAllTestContainer
with BeforeAndAfterAll {
override val container = FixedHostPortGenericContainer("sweetsoft/sapmock",
waitStrategy = Wait.forHttp("/"),
exposedHostPort = 8080,
exposedContainerPort = 8080,
)
override def beforeAll(): Unit = {
}
feature("Process incoming messages") {
info("As a user, I want that incoming messages is going to process appropriately.")
info("A message should contain the following properties: `sap_id`, `sap_event`, `payload`")
当我删除waitStrategy=Wait.forHttp(“/”
)时,它可以正常工作,但与waitStrategy=Wait.forHttp(“/”
它进入超时状态
如何让Testcontainer
监听0.0.0.0
而不是localhost
?
我在这里描述了localhost的问题:0.0.0.0不是可路由的地址。正如您在上一个Q中正确评论的那样,localhost/loopback的规范(v4)地址是127.0.0.1(尽管所有127/8都是为其保留的),但是要从外部连接(或测试)它,您需要使用分配给其接口的实际地址。服务器通常绑定到0.0.0.0以允许它接收所有实际(v4)地址的连接,但每个连接使用一个实际地址,而不是0.0.0。@dave_thompson_085但我必须做什么?0.0.0不是可路由地址。正如您在上一个Q中正确评论的那样,localhost/loopback的规范(v4)地址是127.0.0.1(尽管所有127/8都是为其保留的),但是要从外部连接(或测试)它,您需要使用分配给其接口的实际地址。服务器通常绑定到0.0.0.0以允许它接收所有实际(v4)地址的连接,但每个连接使用一个实际地址,而不是0.0.0.0。@dave_thompson_085但我必须做什么?