Docker 如何修复springboot错误在JRMP连接建立期间检索RMIServer存根失败:javax.naming.CommunicationException错误

Docker 如何修复springboot错误在JRMP连接建立期间检索RMIServer存根失败:javax.naming.CommunicationException错误,docker,maven,spring-data-cassandra,spring-boot-starter,jrmp,Docker,Maven,Spring Data Cassandra,Spring Boot Starter,Jrmp,我对springbootmaven项目和docker中的cassandra有意见。 我想执行mvn verify并在预集成测试中启动cassandra docker和api服务器,执行测试,然后在后集成测试中停止服务器,但我遇到错误无法联系Spring启动应用程序:检索RMIServer存根失败:javax.naming.CommunicationException[根异常为java.rmi.connectionException:JRMP连接建立期间出错; 我已经创建了githubrepo,所

我对
springboot
maven
项目和
docker
中的
cassandra
有意见。 我想执行
mvn verify
并在
预集成测试中启动cassandra docker和api服务器,执行测试,然后在
后集成测试中停止服务器,但我遇到错误
无法联系Spring启动应用程序:检索RMIServer存根失败:javax.naming.CommunicationException[根异常为java.rmi.connectionException:JRMP连接建立期间出错;

我已经创建了
github
repo,所以您可以轻松地重现错误

复制步骤

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
你知道怎么修理吗

p、 美国。 我在mac上工作,这个解决方案也可以在mac和linux上工作。

代码已经修复,现在可以工作了

基本上有两件事改变了:

  • 已从docker-cassandra.sh中删除端口映射9001
  • 在docker cassandra.sh中的cassandra_启动功能中添加了
    sleep 20
    seconds,以便让cassandra有时间正确启动。这不太好,但至少可以工作
  • 现在,下面的代码应该可以在1个集成测试成功执行的情况下工作:

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

    如果您使用的是Windows,那么在2020年解决了一个有点棘手的问题(如果您想阅读全文,请参阅Github上的完整线程)。
    总而言之,解决方案是修复
    jxport

        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
              <jmxPort>9011</jmxPort>
            </configuration>
        [...]
    
    
    org.springframework.boot
    springbootmaven插件
    9011
    [...]
    
    这里的问题是他试图使用一个已经在使用的端口。 我对spring boot也有类似的问题(不是cassandra)

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

    第一种方式:

  • 查找使用该端口的程序(在我的示例中,它是端口9001上的“英特尔(R)图形命令中心”)。(您可以在命令提示符中使用netstat/a/b)或使用tcpview(外部免费程序)
  • 禁用程序
  • 利润
  • 第二种方式

    在spring boot maven插件上的pom中配置jmx端口 (sixro的答复) 但是,我不喜欢这种方式,因为你基本上强迫项目中的其他人使用你的变通方法,而问题在于你的机器