我要评分
获取效率
正确性
完整性
易理解

IllegalArgumentException Reported When Compiling Spring Boot

Symptom

During the test case execution, "IllegalArgumentException: this version does not support 32Bit" is displayed.

Key Process and Cause Analysis

During the compilation, the third-party dependency packages de.flapdoodle.embed.process-2.1.2.jar and de.flapdoodle.embed.mongo-2.2.0.jar do not support the Arm64 architecture. Download and build the mongo and process JAR packages that support the Arm64 architecture.

Conclusion and Solution

  1. Download and build the mongo and process JAR packages that support the Arm64 architecture.
    wget https://mirrors.huaweicloud.com/kunpeng/maven/de/flapdoodle/embed/de.flapdoodle.embed.mongo/2.2.0/de.flapdoodle.embed.mongo-2.2.0.jar
    wget https://mirrors.huaweicloud.com/kunpeng/maven/de/flapdoodle/embed/de.flapdoodle.embed.process/2.1.2/de.flapdoodle.embed.process-2.1.2.jar

    You can also compile and replace the mongo and process JAR packages of the Arm64 architecture by following instructions in de.flapdoodle.embed.mongo-2.2.0.jar Porting Guide and de.flapdoodle.embed.process-2.1.2.jar Porting Guide.

  2. Create a library directory if it does not exist.
    mkdir -p /root/.m2/repository/de/flapdoodle/embed/de.flapdoodle.embed.mongo/2.2.0
    mkdir -p /root/.m2/repository/de/flapdoodle/embed/de.flapdoodle.embed.process/2.1.2
  3. Move the downloaded JAR package to the corresponding directories.
    \cp de.flapdoodle.embed.mongo-2.2.0.jar /root/.m2/repository/de/flapdoodle/embed/de.flapdoodle.embed.mongo/2.2.0
    \cp de.flapdoodle.embed.process-2.1.2.jar /root/.m2/repository/de/flapdoodle/embed/de.flapdoodle.embed.process/2.1.2
  4. This document uses MongoDB 4.0.12 as an example to describe how to replace other versions used in the test cases.
    cd spring-boot-project/spring-boot-autoconfigure
    sed -i "s/3\.5\.5/4\.0\.12/g" `grep -rl "3\.5\.5"`
    sed -i "s/3\.4\.1/4\.0\.12/g" `grep -rl "3\.4\.1"`
    sed -i "s/3_4_15/4_0_12/g" `grep -rl "3_4_15"`
    cd ../../
  5. Create a /root/.embedmongo/extracted/Linux-B64--4.0.12 directory.
    mkdir -p /root/.embedmongo/extracted/Linux-B64--4.0.12
  6. Compile MongoDB by referring to MongoDB 4.0.12 Porting Guide.
  7. Replace the MongoDB in the local repository with the compiled one.
    \cp /usr/local/mongo/bin/mongod /root/.embedmongo/extracted/Linux-B64--4.0.12  && mv /root/.embedmongo/extracted/Linux-B64--4.0.12/mongod /root/.embedmongo/extracted/Linux-B64--4.0.12/extractmongod

    If other versions of MongoDB are used, compile and replace de.flapdoodle.embed.mongo-2.2.0.jar by referring to de.flapdoodle.embed.mongo-2.2.0.jar Porting Guide. Otherwise, an error may occur due to different versions.

  8. For MongoDB 4.0 or later versions, after replsetName is set, NoJournal must be set to false. In addition, you need to modify the EmbeddedMongoAutoConfiguration.java file.
    1. Modify the EmbeddedMongoAutoConfiguration.java source code.
      vim ./spring-boot-project/spring-boot-autoconfigure//src/main/java/org/springframework/boot/autoconfigure/mongo/embedded/EmbeddedMongoAutoConfiguration.java
    2. Press i to enter the insert mode and add the following content to the file:
      • Add the following content below line 32:
        import de.flapdoodle.embed.mongo.config.MongoCmdOptionsBuilder;

      • Add the following content below line 133:
                                if (replSetName != null) {
                                        MongoCmdOptionsBuilder optionsBuilder = new MongoCmdOptionsBuilder();
                                        optionsBuilder.useNoJournal(false);
                                        builder.cmdOptions(optionsBuilder.build());
                                }

        Run the :set list command to check the format. Spaces are not allowed. Use Tab to indent the code.

    3. Press Esc, type :wq!, and press Enter to save the file and exit.