微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

如何修复 springboot 错误无法检索 RMIServer 存根:在 JRMP 连接建立期间出现 javax.naming.CommunicationException 错误

如何解决如何修复 springboot 错误无法检索 RMIServer 存根:在 JRMP 连接建立期间出现 javax.naming.CommunicationException 错误

我在 springboot 中遇到 maven cassandra 项目和 docker 问题。 我想执行 mvn verify 并在 pre-integration-test 中启动 cassandra docker 和 api 服务器,执行测试,然后在 post-integration-test 中停止服务器,但我面临错误 Could not contact Spring Boot application: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment;

我创建了 github 存储库,以便您可以轻松重现错误

重现步骤

git clone https://github.com/gandra/docker-cassandra-with-initial-seed.git
cd docker-cassandra-with-initial-seed
mvn verify

这会产生如下错误

[INFO]
[INFO] --- spring-boot-maven-plugin:2.2.2.RELEASE:start (api-server-start) @ docker-cassandra-with-initial-seed ---
[INFO] Attaching agents: []
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  18.501 s
[INFO] Finished at: 2021-01-21T18:39:05+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:2.2.2.RELEASE:start (api-server-start) on project docker-cassandra-with-initial-seed: Could not contact Spring Boot application: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is:
[ERROR]     java.io.EOFException]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors,re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions,please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

知道如何修复。

附言 我在 mac 上工作,这个解决方案也适用于 mac 和 linux。

解决方法

如果您使用的是 Windows,那么在 2020 年解决了一个问题,这个问题有点难找(here Github 上的完整主题,如果您想阅读全文)。
回顾一下,解决方案是修复 jmxPort。例如:

    <plugin>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-maven-plugin</artifactId>
        <configuration>
          <jmxPort>9011</jmxPort>
        </configuration>
    [...]
,

代码 https://github.com/gandra/docker-cassandra-with-initial-seed 已修复,现在可以使用了。

基本上改变了两件事:

  1. 从 docker-cassandra.sh 中删除了端口映射 9001。
  2. sleep 20 中的 cassandra_start 函数中添加了 docker-cassandra.sh 秒,以便给 cassandra 时间正确启动。不太好,但至少可以工作。

现在后续代码应该可以与 1 个成功执行的集成测试一起使用:

git clone https://github.com/gandra/docker-cassandra-with-initial-seed.git
cd docker-cassandra-with-initial-seed
mvn verify
,

这里的问题是他试图使用一个已经在使用的端口。 我在 spring boot 上遇到了类似的问题(不是 cassandra)。

我认为有两种方法可以解决这个问题:

第一种方式:

  1. 找到使用该端口的程序(在我的例子中是端口 9001 上的“Intel(R) Graphics Command Center”)。 (您可以在命令提示符下使用 netstat /a /b)或使用 tcpview(外部免费程序)
  2. 禁用程序
  3. 利润

第二种方式

在 spring-boot-maven-plugin 上的 pom 中配置 jmx 端口 (来自 Sixro 的回答) 但是,我不喜欢这种方式,因为您基本上是强迫项目中的其他人使用您的解决方法,而问题出在您的机器上。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。