Springboot microservice project packaging. What you need to know, the problems encountered in the springboot multi-module project mvn packaging-there are dependencies but the symbols cannot be found

Reference from: https://blog.csdn.net/SnailMann/article/details/81710461

Before, I was practicing a springcloud microservice project. The project is very simple, a parent class, a registry, a provider, and a consumer. But after the project is written, the project packaging always fails. Always prompt java entity class to have a problem. I was entangled for a long time and finally solved it. Here is a summary.

What is the problem? Let me elaborate. The problem is roughly like this:

I have a SpringCloud project, and each microservice is a SpringBoot project. One of the payment projects depends on a common-util project. Both the payment project and the common project belong to the child module of the same parent project.

  • At this point I want to deploy the integrated SpringCloud project to the server. At this time, I need to open the jar package, put the jar on the server, and start the SpringBoot project through the java -jar *.jar command
  • First of all, I must enter mvn clean install -DskipTests=true to package the common module into the local warehouse
  • Then I package the payment project mvn clean package -DskipTests=true
  • Then the mvn command error (cannot find the symbol), and payment cannot find the class in common, so an error is reported and cannot be packaged

The reason for my analysis:

  • I first checked whether the pom of the parent project missed the module common project, and found that it was not. Payment and common are both child modules of the same parent project, and the <parent> of the child projects are also the same parent project.
  • Then I checked whether there was a problem with the common path or version number that payment relied on, and found that it was correct.
  • Then I check whether the package is not marked in the .m2 warehouse or the package is incomplete. After inspection, I found nothing
  • Then I doubted whether the dependency configuration of pom.xml was a problem, but the problem of unsuccessful packaging of springboot multi-module projects on the Internet did not get any results

The final solution:

This solution was solved by a big guy after I asked for help from a certain group. Thank you very much for helping me solve the problem that troubled me all afternoon. 

è¿éåå¾çæè¿ °

My problem is that spring-boot-maven-pluginplug-ins are imported into the pom of the common project , which causes the common jar package to be typed differently from the usual jar package. When the jar package is dependent on other modules, it will appear that the jar cannot be accessed by other modules.

 <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

So if your project Module is only used as a jar package dependency, and not a SpringBoot startup project, don't spring-boot-maven-pluginconfigure the plug-in to the project's pom. The jar package typed when the plug-in is imported is different from the jar package typed without the plug-in. Remember

to sum up

In a distributed microservice project, add the above dependencies to the pom file of the project that needs to be started. The entity classes, tool classes, etc. do not need to be started, only need to be inherited, and the services of dependent modules do not need the above rely. There is no need to add the above dependencies in the parent project. As long as they all directly or indirectly inherit the parent project, the parent project packaging will package other dependent services.

Guess you like

Origin blog.csdn.net/wjg1314521/article/details/105076927