SpringBoot solve the problem of multi-module release?

  

image.png

 

  If you are using a multi-module SpringBoot published to external Tomcat, you may encounter a variety of problems. This article summarizes the solution in the following eight principles that often appear when and publish four issues, mastered these principles and solutions can solve almost overwhelming number SpringBoot post questions.

  SpringBoot multi-module released eight major principles

  1 in the publishing module packaging, rather than on the parent module package

  For example, the following project directory:

  

image.png

 

  If you want to publish it on its api module package directly, rather than packaged on the parent module.

  Public calling module 2, to the packaging type jar format

  A common module, such as the model and the need to set common packaging format to jar arranged in pom.xml:

  jar

  3 is set to release the module packaging type format war

  Set in a release module in pom.xml:

  war

  4 exclude built-tomcat

  Set in a release module in pom.xml:

  

 

  When setting the scope = provided, this jar package does not appear in the article in a publication, which ruled out the built-in tomcat.

  5 Set the startup class

  This step corresponds to the entrance tell tomcat where to start. Need to add the following code startup class:

  

 

  6 If you are using interceptors must exclude static files

  For example, I use a swagger in the project, then I need to exclude static files swagger, the code is as follows:

  

 

  7 is first loaded with a common module, and then publish the project

  If the release of the module references other public modules of the project, the public need to first module of this project is loaded into the local repository.

  Operation, double-click the parent module to install, after install successfully, click Publish package generation module package of war, to complete the package of the project, as shown below:

  

 

  8 deployment project

  With After war package, the package need only a single war, into tomcat webapps directory, to restart tomcat, as shown below:

  

image.png

 

  Item normal operation will generate the same name in the directory webapps folder, as shown below:

  

image.png

 

  The configuration is complete, you can project your own happy visit the release.

  Possible problems and solutions

  One problem: SpringBoot configure the port number does not affect the film release program?

  A: does not affect the configuration of server.port will be covered to prevail itself tomcat port number, the port number configured in tomcat tomcat / config / server.xml file.

  Question two: Publish error, you can not find other modules or project modules in public, how to do?

  A: Because there is no parent node operation to perform install the maven, is to install the module into the local public warehouses, available to other projects.

  Question three: can not find main class SpringBoot running, how do?

  A: Because the class is not set to start due to set ways:

  pom.xml startup class configuration, the configuration configurationmainClasscom.bi.api.ApiApplication / mainClass / configuration.

  Start class inheritance SpringBootServletInitializer implemented SpringApplicationBuilder method, described with reference to the specific code in the fifth part.

  Question 4: deploying to Tomcat 7 SpringBoot project has been able to find xxx.jar package?

  A: This is because SpringBoot version is too high, tomcat version is too low causes. If you are using the latest version of SpringBoot, consider the tomcat also upgraded to the latest version of tomcat 8.x +, we can solve this problem.

  

Guess you like

Origin blog.csdn.net/qianfeng_dashuju/article/details/93496951