Solve 99% of problems SpringBoot multi-module release? Solutions SpringBoot released eight principles and four issues

image.png

If you are using a multi-module project SpringBoot, you may encounter a variety of problems at the time of publication. 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 api it on its packaging module directly, rather than packaged on the parent module.

Public calling module 2, to the packaging type jar format

Common module, for example common , and model needs to be set packaging to jar the format, in pom.xml the configuration:

<packaging>jar</packaging>

3 is set to release the module packaging type format war

In module posted  pom.xml settings:

<packaging>war</packaging>

4 exclude built-tomcat

In module posted pom.xml settings:

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <scope>provided</scope>
</dependency>

When set scope=provided , the jar package does not appear in this 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:

@SpringBootApplication
public class ApiApplication extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(ApiApplication.class);
    }
    public static void main(String[] args) {
        SpringApplication.run(ApiApplication.class, args);
    }
}

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:

@Configuration
public class WebMvcConfig extends WebMvcConfigurationSupport {
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        // 排除静态文件
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");
    }
    // do something
}

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 install can, install after a successful, click the Publish module package generates war package, to complete the package of the project, as shown below:
image.png

8 deployment project

With the war after the package, just need a single war package into tomcat's webapps directory and restart tomcat can, as shown below:
image.png
Project running will generate the same name as the folder in the webapps directory, 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: No impact configuration server.port will be covered to the port number tomcat itself prevail, tomcat port number in the tomcat/config/server.xml  configuration 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 configuration startup class configuration configuration><mainClass>com.bi.api.ApiApplication</mainClass></configuration> .
  • Start class inherits 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 www.cnblogs.com/vipstone/p/11059145.html