I am having issue with springboot maven project and cassandra in docker. I want to execute mvn verify and in pre-integration-test to start cassandra docker and api server, execute test and then in post-integration-test to stop server but I am facing error 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;

I have created github repo so you can easily reproduce error.

Steps to reproduce:

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

this will produce error like this:

[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

Any idea how to fix.

p.s. I am working on mac and this solution would work on mac and linux as well.

3

There are 3 best solutions below

0
On BEST ANSWER

Code https://github.com/gandra/docker-cassandra-with-initial-seed is fixed and now working.

Basically 2 thing are changed:

  1. Removed port mapping 9001 from docker-cassandra.sh.
  2. Added sleep 20 seconds in cassandra_start function in docker-cassandra.sh in order to give time cassandra to properly boot up. Not nice but at least working.

Now followiung code should work with 1 integration test executing successfully:

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

If you are using Windows, there was an issue solved in 2020 that is a little bit tricky to find (here the complete thread on Github if you want to read the full story).
Just to recap, the solution is to fix the jmxPort. For example:

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

The problem here is that he tries to use a port that is already in use. I had a similar problem with spring boot (not with cassandra).

Two ways i see to solving this:

First way:

  1. Find the program that is using that port (in my case it was "Intel(R) Graphics Command Center" on port 9001). (you can use netstat /a /b in command prompt) or use tcpview (external free program)
  2. disable the program
  3. Profit

Second way

configuring the jmx port in your pom on the spring-boot-maven-plugin (Answer from sixro) BUT, i don't like this way because you basically force the others in your project to use your workaround, while the issue is on your machien.